function resetFormAll() {
	if( $('form').length > 0 ){
		$(':input','form').not(':button, :submit, :reset, :hidden').val('').removeAttr('checked').removeAttr('selected');
	}		
};
function init(){
	function megaHoverOver(){

		$(this).find(".sub").stop().fadeTo('fast', 1).show();
			
		//Calculate width of all ul's
		(function($) { 
			jQuery.fn.calcSubWidth = function() {
				rowWidth = 0;
				//Calculate row
				$(this).find("ul").each(function() {					
					rowWidth += $(this).width(); 
				});	
			};
		})(jQuery); 
		
		if ( $(this).find(".row").length > 0 ) { //If row exists...
			var biggestRow = 0;	
			//Calculate each row
			$(this).find(".row").each(function() {							   
				$(this).calcSubWidth();
				//Find biggest row
				if(rowWidth > biggestRow) {
					biggestRow = rowWidth;
				}
			});
			//Set width
			$(this).find(".sub").css({'width' :biggestRow});
			$(this).find(".row:last").css({'margin':'0'});
			
		} else { //If row does not exist...
			
			$(this).calcSubWidth();
			//Set Width
			//$(this).find(".sub").css({'width' : rowWidth});
			
		}
	}
	
	function megaHoverOut(){ 
	  $(this).find(".sub").stop().fadeTo('fast', 0, function() {
		  $(this).hide(); 
	  });
	}


	var config = {    
		 sensitivity: 2, // number = sensitivity threshold (must be 1 or higher)    
		 interval: 100, // number = milliseconds for onMouseOver polling interval    
		 over: megaHoverOver, // function = onMouseOver callback (REQUIRED)    
		 timeout: 500, // number = milliseconds delay before onMouseOut    
		 out: megaHoverOut // function = onMouseOut callback (REQUIRED)    
	};

	$("ul#nav li .sub").css({'opacity':'0'});
	$("ul#nav li").hoverIntent(config);
	
	var isOpen = true;
	$('#panel > .button').click(function() {
		if (isOpen) {
			$(this).parent().stop(true, true).animate({width: '283'}, 'fast',function(){
				$('#panel > .content').show();	
			});
		} else {
			$('#panel > .content').slideUp('fast', function(){
				$(this).parent().stop(true, true).animate({width: '35'}, 'fast',function(){});
			});
		}
		isOpen = !isOpen;
	});
	
	if($('#myForm').length>0){
		var form_valSetting = {fields : [
			 {id:"CFirst", msg:"Please fill in your first name.", type:""},
			 {id:"CLast", msg:"Please fill in your last name.", type:""},
			 {id:"Phone", msg:"Please fill in your phone number.", type:""},
			 {id:"CEmail", msg:"Please fill in your email address so I may contact you.", type:"email"},
			 {id:"Message", msg:"Please type a message.", type:""}
			 //,{id:"recaptcha_response_field", msg:"Recaptcha is a required field", type:"recaptcha"}
		]};
		var form_msgSuccess = function(){
			var name = $('#CFirst').val();
			var email = $('#CEmail').val();		
			$('#myForm').slideUp("normal", function() {				   							
				$('#myForm').before(
					'<div style="clear:both">\n \
						<br /><div style="font:bold 20px/1.5em Arial, Helvetica, sans-serif">Hi '+name+',</div><br />\n \
						<div style="font:normal 12px/1.5em Arial, Helvetica, sans-serif">\n \
							Thanks for contacting us. <br />\n \
							One of us from Voyager will be contacting you via <b>'+email+'</b> just as soon as we can.\n \
						</div>\n \
					</div>'				
				);
			});	
		};	
		var form_init = new WIN.validateForm( 'submit', form_valSetting, 'contact_process.php', form_msgSuccess, null );
	}
};
function myslider(){
	if($(".wrapperFolio").length>0){
		$(".wrapperFolio .paging").show();
		$(".wrapperFolio .paging a.links:eq(0)").addClass("active");
		$(".wrapperFolio .dAll:eq(0)").addClass("active");
			
		var imageWidth = $(".wrapperFolioImg").width();
		var imageSum = $(".wrapperFolioImgInner img").size();
		var imageReelWidth = imageWidth * imageSum;
		$(".wrapperFolioImgInner").css({'width' : imageReelWidth});
		
		rotate = function(){	
			var triggerID = $active.attr("rel") - 1; 
			var triggerID2 = $active.attr("rel"); 
			if(triggerID2!='prev' || triggerID2!='next'){
				var wrapperFolioImgInnerPosition = triggerID * imageWidth; 
				
				$(".wrapperFolio .paging a.links").removeClass('active'); 
				$active.addClass('active'); 
				$(".wrapperFolio .dAll").removeClass('active');
				$(".wrapperFolioImgInner").animate({ 
					left: -wrapperFolioImgInnerPosition
					}, 500, function() {
					   $(".wrapperFolio .dAll:eq("+triggerID+")").addClass("active");
				   }
				);
			}
		}; 
		rotateSwitch = function(){	
			play = setInterval(function(){ 
				var p_id = ($('.wrapperFolio .paging a.links.active').attr('rel'));		
				var p_len = $(".wrapperFolio .paging a.links").length;
				if(p_id==p_len){
					$active = $('.wrapperFolio .paging a.links:eq(0)');
				}
				else {
					$active = $('.wrapperFolio .paging a.links.active').next();
				}
				rotate(); 
			}, 7000);
		};
		rotateSwitch(); 
		
		$(".wrapperFolioImgInner a").hover(function(){clearInterval(play);},function(){rotateSwitch();});	
		$(".wrapperFolio .paging a.links").click(function() {	
			$active = $(this); 
			clearInterval(play); 
			rotate(); 
			rotateSwitch(); 
			return false;
		});	
		$(".wrapperFolio .paging a.ex").click(function() {	
			var p_opt = $(this).attr('rel');
			var p_len = $(".wrapperFolio .paging a.links").length;
			var p_id = $(".wrapperFolio .paging a.links.active").attr('rel');
			if(p_opt=='prev'){
				if(p_id=='1'){
					$(".wrapperFolio .paging a.links:eq("+(p_len-1)+")").trigger('click');
				} else {
					$(".wrapperFolio .paging a.links.active").prev('a').trigger('click');
				}
			} else {
				if(p_id==p_len){
					$(".wrapperFolio .paging a.links:eq(0)").trigger('click');
				} else {
					$(".wrapperFolio .paging a.links.active").next('a').trigger('click');
				}		
			}
			return false;
		});				
	}
};

/*dom ready*/
jQuery(document).ready(function($) {
	//resetFormAll();							
	init();
	myslider();
	if($("a.iframe").length>0){
		$('a.iframe').fancybox({
			'hideOnContentClick'	: false,
			'hideOnOverlayClick'	: false,
			'frameWidth'			: 450,
			'frameHeight'			: 590,
			'zoomSpeedIn'			: 300, 
			'zoomSpeedOut'			: 300,
			'overlayShow'			: true,
			'overlayOpacity'		: 0.6,
			'overlayColor'			: '#555'
		});		
	}
	if($("a.zoom2").length>0){
		$("a.zoom2").fancybox({ 'frameWidth': 705, 'frameHeight': 430, 'overlayShow': true, 'overlayOpacity': 0.6, 'overlayColor': '#555' });
	}
	if($("a.iframeWide").length>0){
		$("a.iframeWide").fancybox({ 'frameWidth': 960, 'frameHeight': 415, 'overlayShow': true, 'overlayOpacity': 0.6, 'overlayColor': '#555' });
	}	
});
