﻿//------: CHECK BROWSER
var version = "";
var browser ="";
var isIE6 = false;

function getBrowser() {	
	if (navigator.appVersion.indexOf("MSIE")>0){
		version = parseFloat(navigator.appVersion.split("MSIE")[1]);  
		browser = "MSIE";
	} else {
		browser = "not MSIE"
	}
}
getBrowser();

if(browser=="MSIE"){
	if(version<7){
		isIE6 = true;
	}
}
//------: GENERAL FUNCTIONS
function toggleClasses(objId,cssName){
	$('.'+cssName).removeClass(cssName);	
	$('#'+objId).addClass(cssName);
}
function switchOnOffClass(objId,cssName){
	var hasClass = $('#'+objId).hasClass(cssName);
	if(hasClass){
		$('#'+objId).removeClass(cssName);
	} else {
		$('#'+objId).addClass(cssName);
	}
}
function toggleVisible(idToHide,idToShow){	
	$('#'+idToHide).hide();
	if(idToShow)
		$('#'+idToShow).show();
}
function focusOut(){
	$('a').blur();
}
function LoginInput(obj, dValue, setValue){
	if(obj.value==dValue)
		obj.value = setValue;
}
function closeHighSlide(imgId){
	return hs.close(imgId);
}

function DoPopup(TheURL) {
	DoPopupAdvanced(TheURL, 'oPopup', -1, -1, 700, 600, 'yes', 'yes', 'no', 'no', 'no', 'no', 'no');
}

function DoPopupAdvanced(theURL, theWinName, theLeft, theTop, theWidth, theHeight, theresize, thescrollbars, thestatusbar, themenu, thetools, thelocationbar, thedirs) {
	// EXAMPLE doPopup('popup.asp', 'popwin', 10, 10, 500, 300, 'no', 'no', 'yes', 'no', 'no', 'no', 'no')
	// USE theLeft AND theTop = -1 FOR AUTO-CENTER

	if (theLeft == -1 && theTop == -1) {
		theLeft = (screen.width - theWidth) / 2;
		theTop = (screen.height - theHeight) / 2;
	}
	var paramstr;
	paramstr = "width=" + theWidth + "px,height=" + theHeight + "px,left=" + theLeft + "px,top=" + theTop + "px,resizable=" + theresize + ",scrollbars=" + thescrollbars + ",status=" + thestatusbar + ",menubar=" + themenu + ",toolbar=" + thetools + ",location=" + thelocationbar + ",directories=" + thedirs;
	newwindow = window.open(theURL, theWinName, paramstr);
	if (window.focus) { newwindow.focus() }
	return false;
}


function ViewImage(TheImg, TheAlt) {
	TheURL = "/Assets/ViewImage.aspx?Img=" + TheImg + "&Alt=" + TheAlt
	DoPopupAdvanced(TheURL, 'oEnlarge', -1, -1, 700, 600, 'yes', 'yes', 'no', 'no', 'no', 'no', 'no');
}



//------: LIST GALLERY SCRIPTS: START
var allowExpand = true; // Allow expand of highslide by default
function Gallery(aId,prevnext,array){
	var img = $('#'+aId+'>img.image');
	var changePage = false;
	var objImage = new Image();
	var Len = array.length;
	var cpage = getCurrentPage(img,array);
	var thePage;
	$('.prevnextBtns').removeClass("disabled");
		
	switch(prevnext){
		case "prev":
			if(cpage>0){
				changePage = true;
				thePage = cpage-1;
				if(thePage==0){
					$('.prevImg').addClass("disabled");
				}
			}
			break;
		case "next":
			if(cpage<(Len-1)){
				changePage = true;
				thePage = cpage+1;
				if(thePage>=Number(Len-1)){
					$('.nextImg').addClass("disabled");
				}
			}
			break;
	}
	
	if(changePage){
		allowExpand = false;
		$('.prevnextBtns').css("display","none");
		objImage.src=array[thePage].Thumb;
		$('#'+aId).attr("href",array[thePage].Large);
		$('#'+aId).animate({ 'opacity': 0 }, 500, function () {
			objImage.onLoad=GalleryImageLoaded(aId,img,objImage.src);
		});
	}
	
}
function GalleryImageLoaded(aId,img,imgsrc){
	img.attr("src",imgsrc);
	$('#'+aId).animate({ 'opacity': 1 }, 500);
	$('.prevnextBtns').css("display","block");
	allowExpand = true;
}
function getCurrentPage(img,array){
	var Len = array.length;
	var theImage;
	var cImage = img.attr("src");	
	if (cImage.substr(0,7) != "http://") { 
		theImage = cImage;
	} else {		
		theImage = cImage.substring(imgPath.length);
	}
	if(Len>0){
		for(i=0;i<Len;i++){
			if(theImage==array[i].Thumb){
				return i;
			}
		}
	}
	return null;
}
//------: LIST GALLERY SCRIPTS: END
