var ingelogd = false;
var fbonstart;

function initLoginInfo(){
	var strUrl = pntAppUrl+"index.php?pntType=MojoAfgGebruiker&pntHandler=GetLoginInfoAction";
	strUrl+= '&PHPSESSID='+PHPSESSID;	
	strUrl+= '&pntSessionId='+pntSessionId;	
	$.ajax({ url: 	strUrl, success: handleLoginInfoCallbacks   });			
}

function handleLoginInfoCallbacks(data){
	ingelogd = (data.length>0);
	if (ingelogd) printLoginLink(data);
	if (ingelogd) hideFrontPageLoginPart();
}

function printLoginLink(loginLink){	
	var loginLi = document.getElementById('loginLink');	
	if (!pntIsDefined(loginLi)) return;
	loginLi.innerHTML = loginLink;		
}
function hideFrontPageLoginPart(){
		var loginDiv = document.getElementById('frontPageLoginDiv');	
		if (!pntIsDefined(loginDiv)) return;
		loginDiv.style.display = 'none';
}



$(document).ready(init);
function init() {
	initFancyBoxIeFix();
	initFancyBoxOnImages();
	initFancyBoxOnPopupLink();
	var timer = setTimeout('popUpLoginIfNeeded();', 500); //voor ie7 nodig godver
	initViperFlash();
	
	initLoginInfo();
	//initRandomSlide();	
}

function popUpLoginIfNeeded() {	
	if (typeof(shouldShowLogin)!='boolean') return;
	if (shouldShowLogin) {		
		 $('#loginLink a').click();
	}
}

function initFancyBoxOnImages() {
		$("a.fancybox").fancybox({
				'onStart': fbonstart,
				'margin':0,
				'padding':5,
				'overlayOpacity':0.8,
				'hideOnContentClick': true,
				'transitionIn'	:	'elastic',
				'transitionOut'	:	'elastic',
				'speedIn'		  :	200, 
				'speedOut'		:	200, 
				'titleShow': true,
				'titlePosition': 'inside',
				'showNavArrows':true
		});
		//$("a.fancybox img").hover(imgMouseOver, imgMouseOut);
}

function imgMouseOver() {
	var w = $(this).width();
	var h = $(this).height();		
	$(this).width(w+20);
	$(this).height(h+20);
}

function imgMouseOut() {
	var w = $(this).width();
	var h = $(this).height();		
	$(this).width(w-20);
	$(this).height(h-20);
}
	
function initFancyBoxOnPopupLink() {
	$("a.lightboxpage").fancybox({
		'onStart': fbonstart,
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	600, 
		'speedOut'		:	300,
		'type' : 'iframe',
		'autoDimensions'	: false,
		'width' : 700,
		'height' : 230
	});
}

function initViperFlash() {	
	$('#viperFlash').flash({
		swf:pntAppUrl+'images/vipermedical-header03.swf',
		width: 920,
		height: 350
	}
		);
}	

function initFancyBoxIeFix() {
	jQuery(function($) { 
		if($.fn.fancybox) { 
			fbonstart = ($('.fancybox-ie').length != 0) ? function(){if($('#fbiecssfix').length == 0) $('head').append('<link id="fbiecssfix" rel="stylesheet" type="text/css" media="all" href="'+pntAppUrl+'components/fancybox/jquery.fancybox.1.3.4-iefix.css" />');} : function(){}; 
			//$("#yourfancyboxlink").fancybox({'onStart': fbonstart}); 
     } 



}); 


}


function printDebug() {
	var arg = arguments[0];
	if(typeof(arg)=='undefined')return alert('undefined');
	if(typeof(arg)=='string')return alert(arg);
	if(typeof(arg)=='numeric')return alert(arg);
	if(typeof(arg)=='number')return alert(arg);
	if(typeof(arg)=='boolean')return alert(arg);
	alert(pntInspect(arg));
}


function pntInspect(what) {
    var output = '';
    for (var i in what)
        output += i+ ' = ' + what[i] + '\r\n';
    return(output);
}

function initImgCarousel(){
	$(".thumbs a").click(function(){
		var largePath = $(this).attr("href");
		var bigImg = $(this).attr("rel");

		$("#largeImg").attr({ src: largePath });
		$("#fancybox").attr({ href: bigImg});
		return false;
	});

	$('#productphoto ul li img:first').attr('src', 'images/products/bg_img_thumb-hover.gif');

}
function initImgCarouselThumbHover(){
	$('#productphoto ul li img').hover(
  	function () {
  		$('#productphoto ul li img').attr('src', 'images/products/bg_img_thumb.gif');
    	$(this).attr('src', 'images/products/bg_img_thumb-hover.gif');
  	}, 
  	function () {
    	if($(this).attr('class') != 'thumbclicked') $(this).attr('src', 'images/products/bg_img_thumb.gif');
  	}
	);
}
function initImgCarouselThumbClick(){
	$('#productphoto ul li img').click(
		function(){
			$('#productphoto ul li img').removeClass('thumbclicked');
			$(this).addClass('thumbclicked');
		}
	);
	
}
function hideShopBlockText(){
	$('.shopBlock .text').hide();
}

$(document).ready(hideShopBlockText);
$(document).ready(initImgCarouselThumbHover);
$(document).ready(initImgCarouselThumbClick);

$(document).ready(initImgCarousel);
