//Front end Java Script File

jQuery(document).ready(function() 
{
// Enable Pretty Photo effect for Images 
//		jQuery("a[rel^='prettyPhoto']").prettyPhoto
//				({    
//					animationSpeed: 'normal', 		/* fast/slow/normal */
//					padding: 40, 					/* padding for each side of the picture */
//					opacity: 0.35, 					/* Value betwee 0 and 1 */
//					showTitle: false, 				/* true/false */
//					allowresize: false, 			/* true/false */
//					counter_separator_label: ' of ', /* The separator for the gallery counter 1 "of" 2 */
//					theme: 'light_rounded' 			/* light_rounded / dark_rounded / light_square / dark_square */
//				});
//			
	/* function for changing the back ground on request*/
	
	cmsId = jQuery("#currentPageID").attr("value");
	//changeBackgroundImg(cmsId);
	
	jQuery(".prettyPhoto").click(function(obj){
		obj.preventDefault();
	});
	
});




// =============================================== START ================================================================================================================

//Front end Java Script File

var resizeTimer = null;
$(window).bind('resize', function() {
	if (resizeTimer) clearTimeout(resizeTimer);
		resizeTimer = setTimeout(updateImageDimensions, 100);
});

//$(document).ready(updateImageDimensions);

function findPageHeight(){
	if (typeof window.innerHeight!='undefined') {
		return window.innerHeight;
	}
	if (document.documentElement && typeof
		document.documentElement.clientWidth!='undefined' &&
		document.documentElement.clientHeight!=0) {
		return document.documentElement.clientHeight;
	}
	if (document.body && typeof document.body.clientWidth!='undefined') {
		return document.body.clientHeight;
	}
	return (null);
}

function updateImageDimensions() {
	imgWidth = $('#source_image').width();
	imgHeight = $('#source_image').height();
	bodyWidth = document.body.clientWidth;
	bodyHeight= findPageHeight();
	//alert(bodyHeight+ ' - ' + imgHeight);
	// alert(bodyHeight);
	if(bodyHeight >= imgHeight)
	{
		$('#source_image').css({'height':bodyHeight+'px'});
		$('#source_image').css({'width':'auto'});
		//alert(imgHeight);
	}
	if(bodyWidth > imgWidth)
	{
		$('#source_image').css({'width':'100%'});
		$('#source_image').css({'height':'auto'});
	}
	else if(bodyWidth < imgWidth)
	{
		$('#source_image').css({'height':bodyHeight+'px'});
		$('#source_image').css({'width':'auto'});
	}
}

window.onload = function() 
{
	cmsId = jQuery("#currentPageID").attr("value");
	changeBackgroundImg(cmsId);
//	updateImageDimensions();
};


/* function for changing the back ground on each menu Item*/
function changeBackgroundImg(cmsId)
{
 jQuery.ajax({
    type: "POST",
	data:{cmsId:cmsId},
    url: siteURL+"random_bg.php",
    success: function(msg){
		backgroundimage = siteURL+"_images/_header_images/_frontend/"+msg;
		//alert(bodyid);
		document.getElementById('source_image').src = backgroundimage;
//		$('#source_image').css({'width': '100%'});
//		$('#source_image').css({'height': 'auto'});
		$('#source_image').css({'width': 'auto'});
		var windowheight = $(window).height();
		$('#source_image').css({'height': windowheight+'px'});
		updateImageDimensions();
		
//		document.getElementById(bodyid).style.background = 'url("'+backgroundimage+'") fixed no-repeat center top';
   }
 });
}

//============================== END OF =================================================================================================================================

// ================== OLD ========================================================================================================

function changeBackgroundImg1(cmsId)
{

  jQuery.ajax({
    type: "POST",
	data:{cmsId:cmsId},
    url: siteURL+"random_bg.php",
    success: function(msg){
	
	if(msg!='')
	{
	backgroundimage="_images/_header_images/_frontend/"+msg;
	
	//document.getElementById('body_bg').src = backgroundimage;
	
	document.getElementById('body_bg').style.background = 'url("'+backgroundimage+'") fixed no-repeat center top';
	//jQuery('#home').css("backgroundposition","fixed");
	}
	else
	{
		backgroundimage="_images/cycle-courier.jpg";
		
		document.getElementById('body_bg').style.background = 'url("'+backgroundimage+'") fixed no-repeat center top';
		
		//document.getElementById('body_bg').src = backgroundimage;
	}
	
   }
 });
	//document.getElementById('main_container').style.background = 'url("_images/_background/_original/'+backgroundimage+'")';
}
