﻿function SwapImage(ImageId,NewSrc,otherPath){
	var path = "Assets/Images/";
	if(otherPath){
		path = otherPath;
	}
	document.getElementById(ImageId).src = path + NewSrc;
}
function findPosX(obj){
	        var curtop = 0;
	        if (obj.offsetParent){
		        while (obj.offsetParent){
			        curtop += obj.offsetLeft;
			        obj = obj.offsetParent;
		        }
	        }
	        else if (obj.x)
		        curtop += obj.x;
	        return curtop;
        }



var selectedMenu;
function showmenu(num) {   
    selectedMenu = document.getElementById("menu"+num).className;
    
    var x = 0;
    var y = 0;
                
    var minX = 0;
    var maxX = 942;
    var minY = 0;
    
    //alert(findPosX(document.getElementById("submenu"+num)));
    document.getElementById("submenu"+num).style.display = "block";
    if((parseInt(findPosX(document.getElementById("menu"+num)))+520)>maxX)
    {
        var offx= parseInt(document.getElementById("SubMenuContents"+num).clientWidth);
       
        //document.getElementById("submenu"+num).style.left='-'+ offx.toString() +'px';    
        //document.getElementById("submenu"+num).style. 
        //alert(offx);
    }
	
	document.getElementById("menu"+num).className = "MenuItem Bactive";
	hideSelects("hidden");
}

function hidemenu(num) {	
	document.getElementById("submenu" + num).style.display = "none";	
	document.getElementById("menu"+num).className = selectedMenu;	
	hideSelects("visible");
}

function hideSelects(action) {
    //documentation for this script at http://www.shawnolson.net/a/1198/hide-select-menus-javascript.html
    //possible values for action are 'hidden' and 'visible'
    if (action != 'visible') { action = 'hidden'; }
    if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) { //test for MSIE x.x;
        var ieversion = new Number(RegExp.$1) // capture x.x portion and store as a number
        if (ieversion >= 6 && ieversion < 7) {
            for (var S = 0; S < document.forms.length; S++) {
                for (var R = 0; R < document.forms[S].length; R++) {
                    if (document.forms[S].elements[R].options) {
                        document.forms[S].elements[R].style.visibility = action;
                    }
                }
            }
        }
    }
}



 /*---------------------: Code for Gallery: Start : -------------------*/

        var isMoving = false;
        var timer = 0;

        function delayPress(){
            clearTimeout(timer);
            timer = 0;
            isMoving = false;
        }
        
        function moveGallerySet(direction, buttonClicked, GalleryMove, OtherButton) {
            if(isMoving==false){
			    var thumbsArea = document.getElementById(GalleryMove);
			    var leftMargin = thumbsArea.style.marginLeft;			
			    if (!leftMargin) {
				    leftMargin = 0;
			    }
			    else {
				    leftMargin = leftMargin.replace("px", "");
			    }
			    thumbsArea.style.marginLeft = leftMargin + "px";
			    if (direction == 1) {
				    //check if there is something to show. We need absolute values. Since leftMargin is either
				    //negative or 0, its absolute value is its opposite number. So, what we are looking for, is
				    //whether there is anything hidden to the right. If there is, then the thumbnail area width
				    //must be greater than the sum of the width of the showable area and the amount we've already 
				    //shifted the thumbnail area to the left.
				
				    if (thumbsArea.parentNode.offsetWidth - leftMargin < thumbsArea.offsetWidth - 10) {
					    leftMargin = leftMargin - thumbsArea.parentNode.offsetWidth;
					    slideLeft(thumbsArea.style.marginLeft.replace("px", ""), leftMargin, GalleryMove, 4);
					    //thumbsArea.style.marginLeft = leftMargin + "px";
				    }
				    //Now that we've moved the area, blindly activate the "back" button.
				    document.getElementById(OtherButton).className = document.getElementById(OtherButton).className.substring(0,9);
				    //Also, check whether we need to de-activate the "forward" button. Same rationale as above.				
                    if (thumbsArea.parentNode.offsetWidth - leftMargin >= thumbsArea.offsetWidth-10) {
					    document.getElementById(buttonClicked).className= document.getElementById(buttonClicked).className.substring(0,9)+  " inactive";
				    }
			    }
			    else {
				    //check if there is something to show. We need absolute values. Since leftMargin is either
				    //negative or 0, its absolute value is its opposite number. So, what we are looking for, is
				    //whether there is anything hidden to the left. If there is, then the margin is negative.
				    if (leftMargin < 0) {
					    leftMargin = parseInt(leftMargin) + parseInt(thumbsArea.parentNode.offsetWidth);
					    //The leftmost position is with left margin equal to 0. If we go beyond that, it's an error
					    if (leftMargin > 0) {
						    leftMargin = 0;
					    }
					    slideRight(thumbsArea.style.marginLeft.replace("px", ""), leftMargin, GalleryMove, 4);
					    //thumbsArea.style.marginLeft = leftMargin + "px";
				    }
				    //Now that we've moved the area, blindly activate the "forward" button.
				    document.getElementById(OtherButton).className=document.getElementById(OtherButton).className.substring(0,9);
				    //Also, check whether we need to de-activate the "back" button. Same rationale as above.
				    if (leftMargin >= 0) {
					    document.getElementById(buttonClicked).className = document.getElementById(buttonClicked).className.substring(0,9)+  " inactive";
				    }
			    }
            }

            isMoving = true; 
            timer = setTimeout("delayPress()", 2500);           
		}
		function slideLeft(start, stop, elementId, speed) {
			var i;
			var counter = 0;
			stop=stop;
			//alert(stop);
			for (i = start; i > stop; i--) {
				counter++;
				window.setTimeout("document.getElementById('" + elementId + "').style.marginLeft = '" + i + "px';", (10 / speed) * counter);
				
			}
            timer = setTimeout("delayPress()", (10 / speed) * counter);

		}

		function slideRight(start, stop, elementId, speed) {
			var i;
			var counter = 0;
			stop=stop;
			for (i = start; i < stop; i++) {
				counter++;
				window.setTimeout("document.getElementById('" + elementId + "').style.marginLeft = '" + i + "px';", (10 / speed) * counter);
			}
            timer = setTimeout("delayPress()", (10 / speed) * counter);			
		}

		/*---------------------: Code for Gallery: End : -------------------*/
