var $tabletop;
var $windowtop;

function doSlide(element)
{
var $elementToSlide = $(element).children('.slide');	
elementToSlide = element + " li .slide";
$(elementToSlide).click(
		function() {

			var checkElement = $(this).next();
			
			var $parent = $elementToSlide.parents('ul.slidingpanels');
			$parent = $(element);

			if($parent.hasClass('collapsible') && checkElement.is(':visible')) 
				{
				$(this).next().slideUp('normal');
				}	
			else 
				{
				$(elementToSlide).next().slideUp();
				checkElement.slideToggle('normal');
				}

		}
	);	
}
/* ************************************ ON READY  *****************************************/
$(document).ready(function() 
{
	
	$('#mainnav li ul').css("display","none");
	/*********  sets over class for top menu - subnavigaiton ***********/
	$('#mainnav li.parent').hoverIntent(
		function(){
			$(this).addClass('active').addClass('over');
			$(this).children('ul').animate({opacity:'show', height:'show'}, 'normal');
			}, 
		function(){
			$(this).children('ul').animate({height:'hide'}, 'normal');
			//$(this).removeClass('active').removeClass('over');
			$(this).removeClass('active');
	});
	
	
	/********* innerfade for home page splash *********/
	$('#splash').innerfade({speed: 'slow', timeout: 5000, containerheight: '270px' });
	
	
	/********* clears search input on click *********/
	var searchvalue= $('input#search').val();
	$("input#search").focus(function(){
		if ($(this).val()==searchvalue)								  
			$(this).val('');								   
		});
	// returns back default text on blur
	$("input#search").blur(function(){
		if ($('input#search').val()=="")
			$('input#search').val(searchvalue);					 
		});
	/* [end] search input field  */	
	
	
	/********* scrolling header for specifications table *********/
	// creates duplicate of the table header forthe scrolling header
	
	if ($('table.specs').length>0)
	{
	$('<table width="100%" border="0" cellspacing="0" cellpadding="0" class="specsheading"> </table>').insertBefore('table.specs');
	$('table.specs .tableheading').clone().appendTo('table.specsheading');

	
	// set default right position for scrollingtable heading and negative top position to be invisible at first
	$('table.specsheading').css({"top":"-9999px", "right":$('table.specs').position().right});	
	
	$(window).scroll(function () 
		{
		$tabletop = $('table.specs').position().top;
		$windowtop = $(window).scrollTop();
		
		/* if top coordinate of the window is larger than position of the table show heading */
		if ($windowtop > $tabletop)
			{
			$('table.specsheading').css({"top":$windowtop});			
			}
		else
			{
			$('table.specsheading').css({"top":"-9999px"});		
			}

    	});
	} // end if there is table specs	
	
	/* ------------------------ validation ------------------------  */	

	
	$("#form-contactus").validate({
		rules: {
			"frm-firstname": "required",
			"frm-lastname": "required",
			"frm-company": "required",			
			"frm-phone": "required",
			"frm-email": {
				required: true,
				email: true
			},
			"frm-productservice": "required",	
			"frm-inquiry":"required"
		},
		messages: {
			"frm-firstname": "Please enter your first name.",
			"frm-lastname": "Please enter your last name.",
			"frm-company": "Please enter your company.",
			"frm-phone": "Please enter your phone and in correct format.",
			"frm-email": "Please enter your email as name@domain.com.",
			"frm-productservice": "Please select a service that interests you.",	
			"frm-inquiry":"Please drop us a few lines. "			
		}
	});
	
	$("#form-techsupport").validate({
		rules: {
			"frm-firstname": "required",
			"frm-lastname": "required",
			"frm-company": "required",			
			"frm-phone": "required",
			"frm-email": {
				required: true,
				email: true
			},
			"frm-inquiry":"required"
		},
		messages: {
			"frm-firstname": "Please enter your first name.",
			"frm-lastname": "Please enter your last name.",
			"frm-company": "Please enter your company.",
			"frm-phone": "Please enter your phone and in correct format.",
			"frm-email": "Please enter your email as name@domain.com.",
			"frm-inquiry":"Please drop us a few lines. "			
		}
	});	
	
	$("#form-techsupportrma").validate({
		rules: {
			"frm-firstnamerma": "required",
			"frm-lastnamerma": "required",
			"frm-companyrma": "required",			
			"frm-phonerma": "required",
			"frm-emailrma": {
				required: true,
				email: true
			},
			"frm-inquiryrma":"required"
		},
		messages: {
			"frm-firstnamerma": "Please enter your first name.",
			"frm-lastnamerma": "Please enter your last name.",
			"frm-companyrma": "Please enter your company.",
			"frm-phonerma": "Please enter your phone and in correct format.",
			"frm-emailrma": "Please enter your email as name@domain.com.",
			"frm-inquiryrma":"Please drop us a few lines. "			
		}
	});		
	
	
	/* sliding pannel - for example industry and solutions page*/
	if ($('ul.slidingpanels').length>0)
		{
		$('ul.slidingpanels li div.content').hide(); doSlide('ul.slidingpanels'); 
		}
	
	

});