//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'});
	}
}

jQuery(document).ready(function() 
{
	//changeBackgroundImg();
	//updateImageDimensions();
	init();
	/*code for displaying: generating PHP images*/
	if(document.getElementById('fontImage'))
	{
		text=document.getElementById('fontImage').innerHTML;
		text = w3Trim(text);
		document.getElementById('fontImage').style.background='url("'+siteURL+'spot_detail_image.php?text='+text+'") no-repeat';	
	}   
	if(document.getElementById('bigScreen')){
		jQuery('.mediadefault').media({autoplay:true});
	}
});

function init()
{
	/* for scroll bar */
//	if(document.getElementById("right_content"))
//	{
//		//alert(document.getElementById("right_content").clientHeight)
//		//document.getElementById("right_content").style.height=document.getElementById("right_content").clientHeight;
//	}
	if(document.getElementById("right_content").clientHeight>=404)
	{
		jQuery("#main_container").css({overflow:"visible", height:"404px"});
		jQuery('.scroll_projects_list').jScrollPane();
	}
}
window.onload = function() 
{
	init();
	changeBackgroundImg();
	//updateImageDimensions();
	
};


/* function for changing the back ground on each menu Item*/
function changeBackgroundImg()
{

 var bodyid = jQuery('.home').attr("id");
 var newbodyid = bodyid.split("_");
// /alert('#'+bodyid);
  jQuery.ajax({
    type: "POST",
	data:{page_id:newbodyid[1]},
    url: siteURL+"random_bg.php",
    success: function(msg){
		backgroundimage = siteURL+"_images/background_images/_original/"+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';
   }
 });
}

//function for playing video

function playVideo(videoName)
{
	document.getElementById("bigScreen").innerHTML='<a class="mediaspace" href=\"'+siteURL+'_images/_movie_library/_movie/'+videoName+'\"></a>';
	jQuery('.mediaspace').media({autoplay:true});
}

