// function of TimelessGallery


$(document).ready(function(){
	//***************************************** check browser set shadow *****************************************
	var userAgent = navigator.userAgent.toLowerCase();
	$.browser.chrome = /webkit/.test(navigator.userAgent.toLowerCase());
	
	//***************************************** IE7 z-index fix *****************************************
	var zIndexNumber = 10000;
	$('div').each(function() {
		$(this).css('zIndex', zIndexNumber);
		zIndexNumber -= 10;
	});
	
	//***************************************** submenu *****************************************
	var submenu = null;
	
	$('.menu-container-home ul li').hover(function() {
		$('.submenu1,.submenu2',this).show(0);
	}, function () {
		$('.submenu1,.submenu2',this).delay(300).hide(0);
	});
	
	$('.submenu1,.submenu2').hover(function() {
		$(this).stop().show(0);
	}, function () {
		//$(this).delay(1000).hide(10);
	});

	//***************************************** main slide nav *****************************************
	var ttl_width = 0;
	var leftCount = 1;
	$(".slide img").each(function(){
		if($.browser.chrome){
			$(this).bind('load', function() {
				ttl_width += $(this).width()+7;
				$('.brand-container ul').css({width:ttl_width});
  			});
		}else{
			ttl_width += $(this).width()+7;
			$('.brand-container ul').css({width:ttl_width});
		}
	});
		
	$('.arrow-r').click(function(){
		var newX = ttl_width-975*leftCount;
		if(newX > 975){
			$('.slide').animate( {left: -975*leftCount}, "slow");
			leftCount++;
		}else{
			$('.slide').animate( {left: -975*leftCount}, "slow");
		}
	});
		
	$('.arrow-l').click(function(){
		var newX = 975*leftCount-ttl_width;
		if(newX > -975){
			leftCount--;
			$('.slide').animate( {left: -975*leftCount}, "slow");
		}else{
			$('.slide').animate( {left: 0}, "slow");
		}
	});
	
	setHeight();
});

function setHeight(){
	if($('#menu').height() < $('#right-content').height())
		$('#menu').height($('#right-content').height() + 30);
}

setTimeout('setHeight()', 1000);
function trimForm(form){
	for(var i = 0 ; i  < form.elements.length; i++){
		if(form.elements[i].type == 'text' || form.elements[i].type == 'textarea'){
			form.elements[i].value = trim(form.elements[i].value);
		}
	}
}
// Removes leading whitespaces
function LTrim( value ) {
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
}

// Removes ending whitespaces
function RTrim( value ) {
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
}

// Removes leading and ending whitespaces
function trim( value ) {
	return LTrim(RTrim(value));
}
 function isDate(txtDate){  

   var objDate;  // date object initialized from the txtDate string  
   var mSeconds; // milliseconds from txtDate  
   
   // date length should be 10 characters - no more, no less  
   if (txtDate.length != 10) return false;  
   
   // extract day, month and year from the txtDate string  
   // expected format is mm/dd/yyyy  
   // subtraction will cast variables to integer implicitly  
   var day   = txtDate.substring(8,10)  - 0;  
   var month = txtDate.substring(5,7)  - 1; // because months in JS start with 0  
   var year  = txtDate.substring(0,4) - 0;  
   
   // third and sixth character should be /  
   if (txtDate.substring(4,5) != '-') return false;  
   if (txtDate.substring(7,8) != '-') return false;  
   
   // test year range  
   if (year < 999 || year > 3000) return false;  
   
   // convert txtDate to the milliseconds  
   mSeconds = (new Date(year, month, day)).getTime();  
   
   // set the date object from milliseconds  
   objDate = new Date();  
   objDate.setTime(mSeconds);  
   
   // if there exists difference then date isn't valid  
   if (objDate.getFullYear() != year)  return false;  
   if (objDate.getMonth()    != month) return false;  
   if (objDate.getDate()     != day)   return false;  
   
   // otherwise return true  
   return true;  
 }  

