// JavaScript Document
$(document).ready(function(){
	
	//search box
	

        var oldval = $('#sbox').attr('title');
    
        $('#sbox').focus(function(){
           if($('#sbox').attr('value') == $(this).attr('title')) {
        	   $('#sbox').attr('value', '');
           }
        });

       $('#sbox').blur(function(){
         if($('#sbox').attr('value') == '') {
        	 $('#sbox').attr('value', $(this).attr('title'));          
         }
       });
       
       
       $('#searchbtn').click(function(event){
    	   event.preventDefault();
    	   document.searchfrm.submit(); 
       });
       
	
	//end search box text


	 if (navigator.appVersion.indexOf("MSIE") != -1)
	 {
			 var option = {
						  x:      0, 
						  y:      0, 
						  radius: 9,
						  color:  "#BF8DFF"
			 }
	
			 $("#lefttxt h1").textShadow(option);
			 
			 
			 var option1 = {
						  x:      0, 
						  y:      0, 
						  radius: 10,
						  color:  "#BD78C5"
			 }
	
			 $("#social ul li").textShadow(option1);
	 }
						   
	
	
	//setting width for sitecontent
	
	//var docWidth = getDocWidth();
	//$('#container').css('width', getDocWidth()+'px');
	
	
	//on window resize event
	
	$(window).resize(function() {

  		var winwidth = $(window).width();
		//alert(winwidth);
		$('#container').css('width', winwidth+'px');
		$('#container').css('overflow', 'hidden');
		if(winwidth < 1238)
		{
			//winwidth = winwidth ;	
			winwidth = 1002;
			// $('#container').css('overflow', 'visible');
			$('#colthree').css('display', 'none');
			$('#lastcol').css('display', 'none');
			
			//
			justifyChildElements($('#social ul'));
			
			$('#newsticker').css('display', 'block');	
			
			//newsticker
			
			/*$('#news').innerfade({
				speed: 'slow',
				timeout: 4000,
				type: 'sequence',
				animationtype: 'slide',
			});*/			
			
			$('#news').cycle({ 
			    fx:     'fade', 
			    speed:   300, 
			    timeout: 3000, 
			    next:   '#news', 
			    pause:   1 
			});
			
			$('#hrdiv').css('width', '983px');
			$('#hrdiv1').css('width', '983px');
			$('#galleryheader').css('width', '983px');
			$('#social').css('width', '983px');
			
		}
		else
		{
			winwidth=1238;
			$('#colthree').css('display', 'inline');
			$('#lastcol').css('display', 'inline');
			
			$('#newsticker').css('display', 'none');
			
			$('#news').cycle('stop');

			$('#hrdiv').css('width', winwidth+'px');
			$('#hrdiv1').css('width', winwidth+'px');
			$('#galleryheader').css('width', winwidth+'px');
			$('#social').css('width', winwidth+'px');
		}
		
		$('#wrapper').css('width', winwidth+'px'); 
		
		$('#header').css('width', winwidth+'px');
		$('#header h1').css('width', winwidth+'px');
		$('#header h2').css('width', winwidth+'px');
		
		$('#content').css('width', winwidth+'px');
		
		
		
		$('#threecol').css('width', winwidth+'px');
		

		$('#galleryDiv').css('width', winwidth+'px');
		$('#galleryDiv ul').css('width', winwidth+'px');
		
		
		$('#tableDiv').css('width', winwidth+'px');
		$('#tableDiv table').css('width', winwidth+'px');


		
		$('#hrdiv2').css('width', winwidth+'px');
		
		$('#pager').css('width', winwidth+'px');

		
		$('#footer').css('width', winwidth+'px');
		$('#footer ul').css('width', winwidth+'px');
		justifyChildElements($('#social ul'));
		
	});
	$(window).resize();
	
	//overlay
	$("div.trail-text").attr("style", "display: none;");
	if ($("#galleryDiv ul li, div.trailtext").length) 
	{
		$("#galleryDiv ul li, div.trailtext").mouseenter(function(){
		  $(this).find("div.trailtext").slideDown("fast")
		}).mouseleave(function(){
		  $(this).find("div.trailtext").slideUp("fast")
		});
	}
	




});
		

function getDocWidth() {
	var D = document;
	return Math.max(
	Math.max(D.body.scrollHeight, D.documentElement.scrollWidth),
	Math.max(D.body.offsetHeight, D.documentElement.offsetWidth),
	Math.max(D.body.clientHeight, D.documentElement.clientWidth)
	);
}


function justifyChildElements (ele) {
	var childs = ele.children(':visible'),
		count = childs.size(),
		boxWidth = ele.width(),
		totChildWidth = 0,
		emptySpace = 0,
		childLeftMargin = 0;
	if (count == 0) return;
	childs.each(function (index) {
		totChildWidth += $(this).width();
	});

	emptySpace = boxWidth - totChildWidth - 5; //Error

	childLeftMargin = emptySpace/(count > 1 ? count -1 : 2);

	childs.each(function (index) {
		var me = $(this);
		if (index == 0 && count != 1) {
			me.css('marginLeft', 0);
			return;
		}
		me.css('marginLeft', childLeftMargin);
	});
	
}














