
jQuery(document).ready(function($) {

	$('a[rel="fancybox"]').fancybox({
		'overlayOpacity'     : 0.8,
		'overlayColor'       : '#000',
		'titlePosition'      : 'over',
		'transitionIn'       : 'elastic',
		'transitionOut'      : 'elastic',
		'easingIn'           : 'swing',
		'easingOut'          : 'swing',
		'type'               : 'image',
		'onComplete'         : function() {
			$('#fancybox-wrap').hover(function() {
				$('#fancybox-title').show('slow') ;
			}, function() { 
				$('#fancybox-title').hide('slow') ;
			}) ;
		}
	}) ;

}) ;


/* *******************************************************************************************
 *         POPUP functions                                                                   *
 ******************************************************************************************* */

function popWinOpen(winW,winH,sUrl,sName,iResize,iScroll,iStatus) {
	if (screen) {
		if ((screen.height - winH) < 150) {
			var winX = (screen.width - winW) / 2;
			var winY = 0;
		} else {
			var winX = (screen.width - winW) / 2;
			var winY = (screen.height - winH) / 2;
		}
		var popWindow = window.open(sUrl,sName,"resizable=" + iResize + ",menubar=0,scrollbars=" + iScroll + ",status=" + iStatus + ",width=" + winW + ",height=" + winH + ",top=" + winY + ",left=" + winX + "");
		if (popWindow) popWindow.focus();
	} else {
		window.open(sUrl,sName,"resizable=" + iResize + ",menubar=0,scrollbars=" + iScroll + ",status=" + iStatus + ",width=" + winW + ",height=" + winH);
	}
}


function viewImage(pageId, nbr) {
	popWinOpen(500,600,"/asp/view_image.asp?page_id=" + pageId + "&no="+ nbr,"viewWin",1,0,1) ;
}


function getElementLeft(el) {
	if (!el && this) {
		el = this;
	}
	var posLeft = el.offsetLeft;
	var elPar = el.offsetParent;
	while (elPar != null) {
		posLeft += elPar.offsetLeft;
		elPar = elPar.offsetParent;
	}
	return posLeft;
}


function getElementTop(el) {
	if (!el && this) {
		el = this;
	}
	var posTop = el.offsetTop;
	var elPar = el.offsetParent;
	while (elPar != null) {
		posTop += elPar.offsetTop;
		elPar = elPar.offsetParent;
	}
	return posTop;
}

function rePos() {
	try {
		var oImg = document.getElementById("adminLink") ;
		var oTxt = document.getElementById("unet") ;
		var imgL = getElementLeft(oImg) ;
		var imgT = getElementTop(oImg) ;
		oTxt.style.left = (imgL + 135) + "px" ;
		oTxt.style.top  = (imgT - 50) + "px" ;
	} catch (e) {}
}

if (window.attachEvent) {
	window.attachEvent("onload",      function(){ rePos(); }) ;
} else if (window.addEventListener) {
	window.addEventListener("load",   function(){ rePos(); }, true) ;
}



/* *******************************************************************************************
 *         Set Cookie                                                                        *
 ******************************************************************************************* */

function setCookie(name, value) {
	var sPath = '/';
	var today = new Date();
	var expire = new Date();
	expire.setTime(today.getTime() + 1000*60*60*24*365); // 365 days
	var sCookieCont = name + "=" + escape(value);
	sCookieCont += (expire == null) ? "" : "\; expires=" + expire.toGMTString();
	sCookieCont += "; path=" + sPath;
	document.cookie = sCookieCont;
}


/* *******************************************************************************************
 *         Get Cookie                                                                        *
 ******************************************************************************************* */

function getCookie(Name) {
	var search = Name + "=";
	if (document.cookie.length > 0) {
		var offset = document.cookie.indexOf(search);
		if (offset != -1) {
			offset += search.length;
			end = document.cookie.indexOf(";", offset);
			if (end == -1) {
				end = document.cookie.length;
			}
			return unescape(document.cookie.substring(offset, end));
		}
	}
}
