// JavaScript Document
function el(ObjID) {
	return document.getElementById(ObjID);	
}

var timeout;
function scrollText(ObjID,ObjContainer) {
	var pos = jQuery("#" + ObjContainer).position();
	var ObjWidth = jQuery("#" + ObjID).width();
	
	jQuery("#" + ObjID).css("left",parseInt(960 + pos.left) + 'px').animate({"left": parseInt(pos.left-750) + 'px'},20000,function callback(){
		timeout = setTimeout("scrollText('scrolling-text','page-container')",3000);																															
	});
}


var maxScroll = null;

function handleSliderChange(e, ui){
  	maxScroll = jQuery("#content-scroll").attr("scrollHeight") - jQuery("#content-scroll").height();
  	jQuery("#content-scroll").attr({scrollTop: (100 - ui.value) * maxScroll / 100 });
}

function handleSliderSlide(e, ui){
  	maxScroll = jQuery("#content-scroll").attr("scrollHeight") - jQuery("#content-scroll").height();
  	jQuery("#content-scroll").attr({scrollTop: (100 - ui.value) * maxScroll / 100 });
}

function changePhoto(PhotoID,PhotoName) {
	jQuery("#"+PhotoID+"-href").attr("href","/Resources/Upload/Photos/"+ PhotoName);
	jQuery("#"+PhotoID).attr("src","/Resources/Upload/Photos/VeryBigThumbs/"+ PhotoName);	
}

var openedAct = null;
function showAct(ObjID) {
	if(openedAct != null) {
		jQuery("#act-" + openedAct).fadeOut(500,function callback() {
			if(ObjID == null)
				jQuery("#act-menu").fadeIn(500);
			else
				jQuery("#act-menu").fadeOut(500,function callback() {
					jQuery("#act-" + ObjID).fadeIn(500,function callback() {
						openedAct = ObjID;
					});
				});
		});
	} else {
		if(ObjID == null)
			jQuery("#act-menu").fadeIn(500);
		else
			jQuery("#act-menu").fadeOut(500,function callback() {
				jQuery("#act-" + ObjID).fadeIn(500,function callback() {
					openedAct = ObjID;
				});											  
			});		
	}
	
	if(jQuery("#content-holder").height() > jQuery("#content-scroll").height())	
		jQuery("#content-slider").fadeIn(1000);
}

function changePhotosPage(PhotoCategory,Page) {
	var pos = jQuery("#page-content").position();
	
	jQuery("#loading-message").css("opacity",0).css("color","#FFFFFF").css("display","block").css("width",jQuery("#page-content").width() + 'px').css("height",'385px').css("position","absolute").css("z-index","5").css("left",pos.left).css("top",pos.top).css("background","#000000").html('<div style="margin-top:160px;"><center>Loading...</center></div>').animate({opacity:0.7},300);
	jQuery.post("/Resources/Php/getPhotos.php", {PhotoCategory:PhotoCategory,Page:Page},
		function(data) {
			if(typeof data.output == 'string') {
				jQuery("#page-content").slideUp(300,function callback() {
					jQuery("#page-content").html(data.output).slideDown(1000,function callback() {
						jQuery("#loading-message").animate({opacity:0},300,function callback() {
							jQuery("#loading-message").css("display","none");															 
						});																		   
					});
				});
			}
		},"json"
	);
}

function showIntro() {
	var width = jQuery(window.parent.document).width();
	var height = jQuery(window.parent.document).height();
	
	jQuery("#page-container").css("opacity",0).hide();
	jQuery("#page-intro").css("opacity",0).css("left",0).css("top",0).css("display","block").css("width",width + 'px').css("height",height + 'px').animate({opacity:1},300, function callback() {																																   		var timeout = setTimeout("callbackIntro()",12000);																															
																																																																					
	});
};

function callbackIntro() {
	jQuery('#page-intro').fadeOut(300,function callback() {
		jQuery('#page-container').show().animate({opacity:1},300);
	});
}

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

jQuery(document).ready(function() {
	jQuery(document).pngFix();
	
	if(varShowIntro == true)
		showIntro();
	
	scrollText('scrolling-text','page-container');
	if(el('content-slider')) {
		jQuery("#content-slider").hide();
  	
		jQuery("#content-slider").slider({
			orientation:"vertical",
			value:100,
			animate: true,
			change: handleSliderChange,
			slide: handleSliderSlide
		});
	}
		
	jQuery("#page-content").slideDown(1000);
});

addLoadEvent(function() {
	if(el('content-slider')) {
		if(jQuery("#content-holder").height() > jQuery("#content-scroll").height())	
			jQuery("#content-slider").fadeIn(1000);
	}
});