wW = 0;
wH = 0;

dW = 0;
dH = 0;

curhash = '';
wait4resize=0;

mycarousel_itemList = [];

$("document").ready(function() {

	recalcWH();

	if($.browser.msie && parseInt($.browser.version)<10)
	{	
		$("#tblpma a").text('');
	}
	else
	{
		Cufon.replace("#tblpma a", {fontFamily: 'segoeweb'});
	}
	
	Cufon.replace("h1", {fontFamily: 'segoeweb'});	
	Cufon.replace("h2", {fontFamily: 'segoeweb'});	
	Cufon.replace(".slogan", {fontFamily: 'segoeweb'});	
	
	
		
	$("#tblpma a").click(function(){
	
		//console.log($(this).attr('href'));
		var oldhash = curhash;
		curhash = $(this).attr('href');
		window.location.hash = curhash;
		
		$("#tblpma tbody tr td a").removeClass('current');
		
		//$('.aroundlink33').trigger('mouseout');
		
		
		var elem = '#aaa'+(curhash.replace("#",""));
		var obj = this;
		$(obj).addClass('current');		
		
		$("#outerabs").scrollTo($(elem),500, function(){
			

		});
		
		
		return false;
		
		
	
	});
	
	$("#overlaywrapper #overlaycloser a").click(function(){
		
			$("#overlaywrapper").removeClass('shown');
			
			$("#overlaycontent").html('');
			//$("#overallwrapper").fadeTo('fast',1);
			$("#overlayfull").fadeOut('fast',function(){$("#overlayfull").removeClass('shown');});
			
			
			return false;			
	});
	
	$("#contprint01").click(function() {
	
		win1=window.open("/print/print1.html",'print',"menubar=no,location=no,resizable=no,scrollbars=no,status=no,width=600,height=600");
		return false;
	});
	$("#contprint02").click(function() {
	
		win2=window.open("/print/print2.html",'print',"menubar=no,location=no,resizable=no,scrollbars=no,status=no,width=600,height=600");
		return false;
	});
	
	setTimeout(doTheJob, 3000);

});
$(window).resize(function(){
	if(!wait4resize) 
	{
		wait4resize=1;
		setTimeout('doresize()',1000);
	}	
});
function popuptext(ix)
{
	$("#overlayfull").fadeOut('fast', function(){
		$("#overlayfull").addClass('shown');
		$("#overlayfull").fadeTo('fast',0.5, function(){
			$("#overlayfull").css({width:$(window).width(),height:$(window).height()});
		});		
	});	
	$("#overlaycontent").removeClass('gallery');
	$("#overlaycloser").removeClass('gallery');	
	$("#overlaywrapper").removeClass('gallery');

	$("#overlaycontent").removeClass('video');
	$("#overlaycloser").removeClass('video');	
	$("#overlaywrapper").removeClass('video');

	
	content = $("#hiddencontent-"+ix).html();
	$("#overlaycontent").html(content.replace('CACBCC',''));			
	$("#overlaywrapper").addClass('shown');
	$("#overlaywrapper").css({left:parseInt($(window).width()/2 - $("#overlaywrapper").width()/2)+'px',top:parseInt($(window).height()/2 - $("#overlaywrapper").height()/2)-20+'px'});	
	
	
	Cufon.replace(".overlayheader", {fontFamily: 'segoeweb'});	
	
	//$("#overallwrapper").fadeTo('fast',0.2);
	
	
	
	return false;
}

function mycarousel_itemLoadCallback(carousel, state)
{
	
    for (var i = carousel.first; i <= carousel.last; i++) {
        if (carousel.has(i)) {
            continue;
        }

        if (i > mycarousel_itemList.length) {
            break;
        }

        carousel.add(i, mycarousel_itemList[i-1]);
    }
};

/**
 * Item html creation helper.
 */
function mycarousel_getItemHTML(item)
{
    return '<img src="' + item + '" width="282" height="282" alt="" />';
};
function dogallery(galtxt,clicked)
{

	var elem = $("#"+galtxt+'-gallery');
	var srcelem = $("#hiddencontent-"+galtxt+' .items');
	var position = $(clicked).offset();

	$("#overlayfull").fadeOut('fast', function(){
		$("#overlayfull").addClass('shown');
		$("#overlayfull").fadeTo('fast',0.5, function(){
			$("#overlayfull").css({width:$(window).width(),height:$(window).height()});
		});		
	});	
	var htmlcontent = '<ul id="mycarousel">'/*+$(srcelem).html()*/+'</ul>';	
	$("#overlaycontent").html(htmlcontent).addClass('gallery');			
	$("#overlaycloser").addClass('gallery');
	$("#overlaywrapper").addClass('shown');
	$("#overlaywrapper").addClass('gallery');
	$("#overlaycontent").addClass('gallery');
	//$("#overlaywrapper").css({left:parseInt(position.left-150)+'px',top:parseInt(position.top-150)+'px'});	
	$("#overlaywrapper").css({left:parseInt($(window).width()/2 - $("#overlaywrapper").width()/2)+'px',top:parseInt($(window).height()/2 - $("#overlaywrapper").height()/2)+'px'});	
	
	mycarousel_itemList.length = 0;
	var ccount = $(srcelem).children().size();
	
	$(srcelem).children().each(function(ix,obj){
		mycarousel_itemList.push($(obj).html());	
	});
	
	//console.log(mycarousel_itemList);
	
	$('#mycarousel').jcarousel({
        size: ccount,
        itemLoadCallback: mycarousel_itemLoadCallback
    });

}

function popupvid(ix)
{
	$("#overlayfull").fadeOut('fast', function(){
		$("#overlayfull").addClass('shown');
		$("#overlayfull").fadeTo('fast',0.5, function(){
			$("#overlayfull").css({width:$(window).width(),height:$(window).height()});
		});		
	});	

	$("#overlaycontent").addClass('video');
	$("#overlaycloser").addClass('video');	
	$("#overlaywrapper").addClass('video');

	
	content = $("#hiddencontent-"+ix).html();
	$("#overlaycontent").html(content.replace('CACBCC',''));			
	$("#overlaywrapper").addClass('shown');
	$("#overlaywrapper").css({left:parseInt($(window).width()/2 - $("#overlaywrapper").width()/2)+'px',top:parseInt($(window).height()/2 - $("#overlaywrapper").height()/2)-20+'px'});	
	
	
	Cufon.replace(".overlayheader", {fontFamily: 'segoeweb'});	
	
	//$("#overallwrapper").fadeTo('fast',0.2);
	
	
	
	return false;
}



function doresize()
{
	wait4resize=0;
	recalcWH();
	$("#tblpma a[href="+curhash+"]").trigger('click');
}

function gotopage(ix)
{
	$("#tblpma a[href=#"+ix+"]").trigger('click');
}

function recalcWH()
{
	wW = $(window).width();
	wH = $(window).height();
	/*wW = 300;
	wH = 200;*/
	
	dW = wW * 3;
	dH = wH * 3;
	
	bodyclass="v1";
	
	$("#outerall").css({'width':wW+'px', 'height':wH+'px'});
	
	$("#outerrel").css({'width':dW+'px', 'height':dH+'px'});
	
	$("#outerabs").css({'width':wW+'px', 'height':wH+'px'});
	
	$("#outerall .coconut").css({'width':wW+'px', 'height':wH+'px'});
	
	$("#aaa11").css({'left':'0px', 'top':'0px'});
	$("#aaa12").css({'left':wW+'px', 'top':'0px'});
	$("#aaa13").css({'left':parseInt(wW*2)+'px', 'top':'0px'});
	
	$("#aaa21").css({'left':'0px', 'top':wH+'px'});
	$("#aaa22").css({'left':wW+'px', 'top':wH+'px'});
	$("#aaa23").css({'left':parseInt(wW*2)+'px', 'top':wH+'px'});
	
	$("#aaa31").css({'left':'0px', 'top':parseInt(wH*2)+'px'});
	$("#aaa32").css({'left':wW+'px', 'top':parseInt(wH*2)+'px'});
	$("#aaa33").css({'left':parseInt(wW*2)+'px', 'top':parseInt(wH*2)+'px'});

	if(wW < 1280 || wH < 770)
	{
		bodyclass="v2";
	}
	
	volT = 0;
	if(bodyclass=='v1')
	{
		if(wW > 1278)
		{
			cbW = 1278;
			cbL = parseInt(wW/2 - cbW/2);
		}
		else
		{
			cbW = 1278;
			cbL = 0;		
		}

		if(wH > 799)
		{
			cbH = 799;		
			cbT = 10;
		}
		else
		{
			cbH = 779;
			cbT = -20;		
		}	
		
		$("#footer").css({'top':wH - 41 + 'px'});
		
		$("#footercontent1 .v1").show();
		$("#footercontent1 .v2").hide();
	}
	if(bodyclass=='v2')
	{
		
		
		if(wW > 980)
		{
			cbW = 980;
			cbL = parseInt(wW/2 - cbW/2);
		}
		else
		{
			cbW = 980;
			cbL = 0;		
		}

		if(wH > 600)
		{
			cbH = 600;		
			cbT = 0;
			
			volT = parseInt(wH/2)-parseInt(640/2);
		}
		else
		{
			cbH = 600;
			cbT = 0;		
		}			
		
		$("#footer").css({'top':wH - 26 + 'px'});

		$("#footercontent1 .v2").show();
		$("#footercontent1 .v1").hide();
		
		
	}
	
	
	$(".centerboy").css({'left':cbL+'px', 'top':cbT+'px', 'width':cbW+'px', 'height':cbH+'px'});
	
	$(".volleyball").css({'top':volT+'px'});
	
	
	
	$("body").removeClass("v1").removeClass("v2").addClass(bodyclass);
	
	Cufon.replace("#tblpma a", {fontFamily: 'segoeweb'});
	
	//alert(wH);
	
}

function doTheJob() {
	
	if($.browser.msie && parseInt($.browser.version)<10)
	{	
/*	
		DD_roundies.addRule('.aroundlink11', '8px 0px 0px 0px');		
		DD_roundies.addRule('.aroundlink13', '0px 8px 0px 0px');
		DD_roundies.addRule('.aroundlink31', '0px 0px 0px 8px');
		DD_roundies.addRule('.aroundlink33', '0px 0px 8px 0px');
		DD_roundies.addRule('.aroundlink33', '0px 0px 8px 0px');
*/		
		DD_roundies.addRule('#overlaycontent', '8px 8px 8px 8px');
	}
	
	$("#totalLoading").fadeOut(1000);
	$("#pagemanager").fadeIn(1000);
	$("#outerall").css({'display':'block'});
	if(window.location.hash == '' || window.location.hash == '#22')
	{
		curhash = "#22";
		$("#outerabs").scrollTo($("#aaa22"),0);
		$("a[href=#22]").addClass('current');
	}
	else
	{
		curhash = window.location.hash;
		$("#tblpma a[href="+curhash+"]").trigger('click');
	}
	
}

function playVid()
{
	popupvid('video');
	
	jwplayer('mediaplayer').setup({
		'flashplayer': '/video/player.swf',
		'id': 'playerID',
		'width': '660',
		'height': '372',
		'file': '/video/video1.flv'
	});
	
	
	jwplayer('mediaplayer').play();

	return false;
}


