

// JavaScript Document
jQuery(function() {


	// fire up lightbox on all classed elements
	if(jQuery('.lightbox_05').length != 0)
		{
		jQuery(".lightbox_05").lightBox();
		}
	
		jQuery( ".info_dialog" ).dialog({
					autoOpen: false,
					height: 520,
					width: 820,
					modal: true,
					buttons: { "Close": function() {
							jQuery( this ).dialog( "close" );
						}
					},
					close: function() {
					}
				});
		
		
		jQuery( ".info_dialog_controller" ).click(function() {
			
			jQuery(jQuery(this).attr("dialog_box_id")).dialog("open");
			
			});
	
	
		


	});
	


//Javascript Cookie Setter
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
	}
	
//Javascript Cookie Delete
function deleteCookie(name) {
	var value = ";";
	document.cookie = name+"="+value+"expires=Fri, 27 Jul 2001 02:47:11 UTC; path=/";
	}
	
	

    
////////////////////////////////////////////
//////// galleria Slideshow ///////////////
//////////////////////////////////////////


	jQuery(function() {
			
			if(!jQuery('.gallery_demo_unstyled').length == 0)
				{
				
		
				jQuery('.gallery_demo_unstyled').addClass('gallery_demo'); // adds new class name to maintain degradability
				jQuery('ul.gallery_demo').galleria({
					autoplay: true,
					history   : false, // activates the history object for bookmarking, back-button etc.
					clickNext : true, // helper for making the image clickable
					insert    : '#main_image', // the containing selector for our main image
					onImage   : function(image,caption,thumb) { // let's add some image effects for demonstration purposes
						// fade in the image & caption
						if(! (jQuery.browser.mozilla && navigator.appVersion.indexOf("Win")!=-1) ) { // FF/Win fades large images terribly slow
							image.css('display','none').fadeIn(500);
						}
						caption.css('display','none').fadeIn(500);
						
						// fetch the thumbnail container
						var _li = thumb.parents('li');
						
						// fade out inactive thumbnail
						_li.siblings().children('img.selected').fadeTo(500,0.7);
						
						// fade in active thumbnail
						thumb.fadeTo('fast',1).addClass('selected');
						
						// add a title for the clickable image
						image.attr('title','Next image >>');
						image.addClass('dropShadowSmall');
					},
					onThumb : function(thumb) { // thumbnail effects goes here
						
						// fetch the thumbnail container
						var _li = thumb.parents('li');
						
						// if thumbnail is active, fade all the way.
						var _fadeTo = _li.is('.active') ? '1' : '0.7';
						
						// fade in the thumbnail when finnished loading
						thumb.css({display:'none',opacity:_fadeTo}).fadeIn(1500);
						
						// hover effects
						thumb.hover(
							function() { thumb.fadeTo('fast',1); },
							function() { _li.not('.active').children('img').fadeTo('fast',0.7); } // don't fade out if the parent is active
						)
					}
				});
				
				
				
				}// end if
		});
	









////////////////////////////////////////////////
//////////// jQuery Scripts //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////

// enables javascript prior to files loading
jQuery(document).ready(function(){
// init the map before the tabs
if(is_map)
	{
	//initialize();
	}
	
////////////////////////////
////
//// this is the function for the small scrolling inventory specials list
////    could be --- needs to be extended to support different queries
////
////////////////////////////
	
jQuery(function() {
		
	if(jQuery("#smallInventoryList").length)
		{
		var response = jQuery.ajax({
		type: "POST",
		url: domain + "ajax/ajax-show-InventoryList.php",
		data: "template = small",
		error: function(msg){
			// fail function here
			//alert("error");
			//alert(msg);
	
			},
	   success: function(msg){
			//alert(msg);
			
			// success function here
			jQuery(".smallInventoryList").append(msg);
			
			//alert("success");
			//alertResponse(response);
			}
	
	 });
		}//end of if statement
	
	return false;
	});


////////////////////////////
////
//// this is the function for the 9 grid display of inventory specials list
////    could be --- needs to be extended to support different queries and above function
////
////////////////////////////
	
jQuery(function() {
		
	if(jQuery("#specialList9Grid").length)
		{
		var response = jQuery.ajax({
		type: "POST",
		url: domain + "ajax/ajax-show-Inventory9Grid.php",
		data: "template = small",
		error: function(msg){
			// fail function here
			//alert("error");
			//alert(msg);
	
			},
	   success: function(msg){
			//alert(msg);
			
			// success function here
			jQuery(".specialList9Grid").append(msg);
			
			//alert("success");
			//alertResponse(response);
			}
		//}//end of if statement
	
	 });
	} // end of if statement
	
	return false;
	});


////////////////////////////
////
//// This is an auto cycle function which uses the cycle jquery lib
////    can be used anywhere in site as long as html structure is sound
////   http://malsup.com/jquery/cycle/more.html?v2.23
////////////////////////////

jQuery(function() {
	jQuery('.cycleThis').cycle({ 
		fx:     'fade', 
		timeout: 5000, 
		delay:  -1000 ,
		prev:    '#prev',
		next:    '#next'
		
		
	
	});



    function pagerFactory(idx, slide) {
        var s = idx > 2 ? ' style="display:none"' : '';
        return '<li'+s+'><a href="#">'+(idx+1)+'</a></li>';
    };
    
});

jQuery('#pause').click(function() { 
    jQuery('.cycleThis').cycle('pause'); 
	return false;
});


///////////////////////////////
///// This allows us to disable a 'save' or 'submit' button after the initial click to 
///// keep down multiple form submissions
//////////////////////////////
jQuery(".disable_on_click").submit(function()
  {
	//jQuery(this).attr("disabled","disabled");
	jQuery(this).attr("value"," Saving... ");
  });

///////////////////////////////
///// This is for the locations widget.  
///// It should be able to handle multiple locations in multiple formats
///// Class for the <li> is locationLi
///// Divs that should show or hide are id'd location-{$location.id} (id being the id number of said location)
//////////////////////////////

jQuery(".locationLi").click(function()
  {
	//alert(this.id);
	
	// set all li classes to not the active
	jQuery(".locationLiActive").removeClass("locationLiActive");
	// set the active one
	jQuery(this).addClass("locationLiActive");
	
	
	
	var idWhole = this.id.split("-");
	var id = idWhole[1];
	//alert(id);


	jQuery(".locationDiv").hide();
	jQuery("#location-"+id).show();

	jQuery(".locIndicator").hide();
	jQuery("#locIndicator-"+id).show();


	//alert("here I am");
   //alert(this.title);
   });








//////////////////////////////////////////
//// this sets all locations invisible and shows the first
////////////////////////////////////////

jQuery(function() {
	jQuery(".locationDiv").hide();
	jQuery(".locationDivActive").show();
	});





///////////////////////////////
///// initiates wysiwyg rich text editor
//////////////////////////////

jQuery(function()
{
    jQuery('.wysiwyg').wysiwyg({
							controls : {
							justifyLeft: { visible : true },
							justifyCenter: { visible : true },
							justifyRight: { visible : true },
							justifyFull: { visible : true },
							increaseFontSize: { visible : false },
							decreaseFontSize: { visible : false },
							removeFormat: { visible : false },
							separator01 : { visible : false },
							separator02 : { visible : false  },
							separator03 : { visible : false  },
							separator04 : { visible : false  },
							separator05 : { visible : false },
							separator06 : { visible : false },
							separator07 : { visible : false },
							separator08 : { visible : false },
							separator09 : { visible : false },
							separator10 : { visible : false },
							html: {
									visible: true,
									exec: function()
									{
										if(this.viewHTML){
										  this.setContent(jQuery(this.original).val());
										  jQuery(this.original).hide();
										  jQuery(this.editor).show();
										}
										else{
										  this.saveContent();
										  jQuery(this.original).show();
										  jQuery(this.editor).hide();
										}
							
										this.viewHTML = !( this.viewHTML );
									}
							}
							
							}
						  });
});



///////////////////////////////////
////////  Handles next and previous buttons within tabbed navigation
//////////////////////////////////
jQuery('.next').click(function() { 
		 var $tabs = jQuery('ul.tabs').tabs(); 
		 var selected = $tabs.data('selected.tabs'); 
		 $tabs.tabs('select', selected + 1);
		 return false; 
		 }) 

jQuery('.previous').click(function() { 
		 var $tabs = jQuery('ul.tabs').tabs(); 
		 var selected = $tabs.data('selected.tabs'); 
		 $tabs.tabs('select', selected - 1); 
		 return false; 
		 }) 





//////////////////////////////////////////
///////// Content To Tabs ////////////////////
////////////////////////////////////////

jQuery(function() {
		// normal tabs
		jQuery("div.contentTabs").tabs();
		jQuery("div.addressTabs").tabs();
		jQuery("div.tab1").tabs();
		jQuery("div.tab2").tabs();

		// invisibly loaded tabs (mainly for admin and control panel stuff)
		jQuery("div.invisibleTabs").tabs();
		jQuery("div.invisibleTabs").show();

// vertical tabs next two lines
		jQuery("div.verticalTabs").tabs().addClass('ui-tabs-vertical ui-helper-clearfix');
		jQuery("div.verticalTabs li").removeClass('ui-corner-top');
});


////// this handles adding a hash to browser addy bar
jQuery("div.invisibleTabs ul li a").click(function(){

	//jQuery("#addEditBoat").attr("action",jQuery(this).attr('href'));
	});

///////////////////
/// hover color change for boat search results list
///////////////////
var divListClass = "listBoxBackground";

jQuery('.listBoxSmall').hover(function() {
  
  //divListClass = jQuery(this).attr("class");
  jQuery(this).removeClass(divListClass);
  jQuery(this).addClass('hover');
}, function() {
  jQuery(this).removeClass('hover');
  jQuery(this).addClass(divListClass);

});



//////////////////////////////////////////
///////// makes a table sortable by class
////////////////////////////////////////

	
	



jQuery(document).ready(function() 
    { 
	////////////////////////////////////////////
	//////// sortable table ///////////////
	//////////////////////////////////////////
	if(jQuery('.sortable_table').length > 0)
		{
		jQuery(".sortable_table").tablesorter({
				headers:
				   {  
					 1 : { sorter: "shortDate"  }
				   }, 
				widgets: ['zebra']
			});
		}
    }); 



//////////////////////////////////////////
///////// Kinda a stripped back form validation 
//////// here we only validate the bare necessities such as name and email
////////////////////////////////////////

jQuery(".lead_submit_no_validate").validate({
	rules: {
		name: {
			required: true,
			minlength: 2
		},
		email: {
			required: true,
			email: true
		}
	},
	messages: {
		name: " <span class='red'> -Name Required </span>",
		email: " <span class='red'> -Please enter a valid email address</span>"
	},
	// specifying a submitHandler prevents the default submit, good for the demo
	submitHandler: function(form) {
		// pass and submit the form
		leadSubmit(form);
	}
});

//////////////////////////////////////////
///////// Validates a Lead Submit form
////////////////////////////////////////

// REQUIRED FIELDS
// email
// zip (if country USA or Canada)
// name
jQuery(".validate_lead_submit").validate({
	rules: {
		name: {
			required: true,
			minlength: 2
		},
		email: {
			required: true,
			email: true
		},
		phone: {
			required: true
		},
		zip: {
			required: true,
			minlength: 3
		}
	},
	messages: {
		name: " <span class='red'> -Name Required </span>",
		email: " <span class='red'> -Please enter a valid email address</span>",
		phone: " <span class='red'> -Phone Number Required</span>",
		zip: " <span class='red'> -Zip/Postal Required</span>"
	},
	// specifying a submitHandler prevents the default submit, good for the demo
	submitHandler: function(form) {
		// pass and submit the form
		leadSubmit(form);
	}//,
	// set this class to error-labels to indicate valid fields
	//success: function(label) {
		// set &nbsp; as text for IE
	//	label.html("&nbsp;").addClass("checked");
	//}

});



jQuery(".lead_submit_locator").submit(function(){
		//alert(jQuery(this).attr("id"));
		//alert(form.id);
		//alert(form);
		
		var formID = jQuery(this).attr("id");
		var id = formID.split("-");
		//alert(typeof(id));
		//alert(id.length);
		//return false;
		if(id.length >= 2)
			{
			// this is the id of the response element where resposne message will show
			var responseID = id[0]+"_response-"+id[1];
			var imageID = id[0]+"_image-"+id[1];
			}
		else
			{
			var responseID = formID+"_response-";
			var imageID = formID+"_image-";
			}
		
		jQuery("#"+formID).css('display','none').fadeOut(1000);
		//jQuery("#"+imageID).css('display','none').fadeOut(1000);
		//jQuery("#"+imageID).css('border','0');
		
		// 'this' refers to the current submitted form
		var str = jQuery(this).serialize();
		//alert(str);
		
		   var response = jQuery.ajax({
			   type: "POST",
			   url:  domain+"ajax/NewLead.php",
			   data: str,
			   error: function(msg){
					// fail function here
					alert("error");
					alert(msg);
					var message = "<h3>An error has occured, your request has not been submitted.  Please contact us via Phone. We Apologize for any inconvenience.</h3>";
					jQuery("#"+responseID).append(message);
					jQuery("#"+responseID).css("display","block").fadeIn(1000);
			
					},
			   success: function(msg){
					// success function here
					//alert(msg);
		
					
					var message = "<p class='darkGrey' style='font-style:italic;font-size:1.2em;'>Your questions/comments have been submitted.<br />We will be back with your answers promptly.</p><p style='text-align:right;font-style:italic;margin-right:100px;color:#1969BC;'> Thank You.</p>";
					
					jQuery("#"+responseID).append(message);
					jQuery("#"+responseID).css('display','block').fadeIn(1000);
					
					// fade out the salesman image and fade in email image
					//jQuery("#"+imageID).css('display','block').fadeIn(1000);
					jQuery("#"+imageID).css('border','#ffffff').fadeIn(1000);
					jQuery("#"+imageID).attr('src', domain+'images/users/email.jpg').fadeIn(1000);
					//alert("success");
					//alertResponse(response);
					}
			
			 });
			
			return false;

});

function leadSubmit(form){

		//alert(jQuery(this).attr("id"));
		//alert(form.id);
		//alert(form);
		
		var formID = form.id;
		var id = formID.split("-");
		//alert(typeof(id));
		//alert(id.length);
		//return false;
		if(id.length >= 2)
			{
			// this is the id of the response element where resposne message will show
			var responseID = id[0]+"_response-"+id[1];
			var imageID = id[0]+"_image-"+id[1];
			}
		else
			{
			var responseID = formID+"_response-";
			var imageID = formID+"_image-";
			}
		
		jQuery("#"+formID).css('display','none').fadeOut(1000);
		//jQuery("#"+imageID).css('display','none').fadeOut(1000);
		//jQuery("#"+imageID).css('border','0');
		
		// 'this' refers to the current submitted form
		var str = jQuery(form).serializeArray();
		//alert(str);
		
		   var response = jQuery.ajax({
			   type: "POST",
			   url:  domain+"ajax/NewLead.php",
			   data: str,
			   error: function(msg){
					// fail function here
					alert("error");
					alert(msg);
					var message = "<h3>An error has occured, your request has not been submitted.  Please contact us via Phone. We Apologize for any inconvenience.</h3>";
					jQuery("#"+responseID).append(message);
					jQuery("#"+responseID).css("display","block").fadeIn(1000);
			
					},
			   success: function(msg){
					// success function here
					//alert(msg);
		
					
					var message = "<p class='darkGrey' style='font-style:italic;font-size:1.2em;'>Your questions/comments have been submitted.<br />We will be back with your answers promptly.</p><p style='text-align:right;font-style:italic;margin-right:100px;color:#1969BC;'> Thank You.</p>";
					
					jQuery("#"+responseID).append(message);
					jQuery("#"+responseID).css('display','block').fadeIn(1000);
					
					// fade out the salesman image and fade in email image
					//jQuery("#"+imageID).css('display','block').fadeIn(1000);
					jQuery("#"+imageID).css('border','#ffffff').fadeIn(1000);
					jQuery("#"+imageID).attr('src', domain+'images/users/email.jpg').fadeIn(1000);
					//alert("success");
					//alertResponse(response);
					}
			
			 });
			
			return false;

	}// end leadSubmit function



//////////////////////////////////////////
///////// Subscriber Submit from form on page ////////////////////
////////////////////////////////////////

jQuery(".subscriber-submit").submit(function(){
//alert(jQuery(this).attr("id"));

var formID = jQuery(this).attr("id");
var id = formID.split("-");

// this is the id of the response element where resposne message will show
var responseID = id[0]+"_response-"+id[1];


jQuery("#"+formID).css('display','none').fadeOut(1000);

// 'this' refers to the current submitted form
var str = jQuery(this).serialize();

   var response = jQuery.ajax({
	   type: "POST",
	   url:  domain+"ajax/NewSubscriber.php",
	   data: str,
	   error: function(msg){
			// fail function here
			alert("error");
			alert(msg);
			var message = "<span>An error has occured, your request has not been submitted.  Please contact us via Phone. We Apologize for any inconvenience.</span>";
			jQuery("#"+responseID).append(message);
			jQuery("#"+responseID).css("display","block").fadeIn(1000);
	
			},
	   success: function(msg){
			//alert(msg);
			
			// success function here
			var message = "<img src='"+domain+"images/icons/email.png' style='float:left;'/><p class='darkGrey' style='position:relative;left:10px;margin:0;padding-top:10px;font-size:1.1em;'>Signed-Up!</p> <p class='green' style='font-style:italic;font-size:.8em;text-align:right;'> Thank You.</p>";
			
			jQuery("#"+responseID).append(message);
			jQuery("#"+responseID).css('display','block').fadeIn(1000);
			
			//alert("success");
			//alertResponse(response);
			}
	
	 });
	
	return false;

});

















///////////////////////////////////
////// Selects all inside an input area regardless if the default contnet has been changed
///////////////////////////////////

jQuery(".selectAll").focus(
 function()
 {
   this.select();
 }
)

///////
// similar to above except it checks to see if the default content has been altered and selects all ONLY if the content has NOT been changed
///////

jQuery(".selectAll_default").focus(
 function()
 {
  // only select if the text has not changed
  if(this.value == this.defaultValue)
  {
   this.select();
  }
 }
)




///////////////////////////////////
////// AJAX response alert function
///////////////////////////////////

function alertResponse(response)
	{
		alert(response.responseText);
	}


///////////////////////////////////
////// toggles the next thing after this element
///////////////////////////////////

jQuery('.toggleNext').click(function() {
	jQuery(this).next().slideToggle('fast');
	return false;
	});



jQuery(function(){
      jQuery(".tooltip_title").mbTooltip({ // also jQuery([domElement]).mbTooltip
        opacity : .85,       //opacity
        wait:800,           //before show
        cssClass:"default",  // default = default
        timePerWord:70,      //time to show in milliseconds per word
        hasArrow:false,                 // if you whant a little arrow on the corner
        hasShadow:true,
        imgPath:"images/",
        anchor:"mouse", //or "parent" you can ancor the tooltip to the mouse  or to the element
        shadowColor:"black", //the color of the shadow
        mb_fade:200 //the time to fade-in
      });
});



///////////////////////////////////
////// toggles the next thing after this element
///////////////////////////////////

jQuery('.toggle_feedback').click(function() {
	jQuery("#website_feedback").toggle('fast');
	return false;
	});


///////////////////////////////////
////// drop-down menu control
///////////////////////////////////
jQuery(".drop_down_menu").live('click', function() {
	jQuery(this).next().slideToggle('fast');
	return false;
	});

///////////////////////////////////
////// drop-up menu control
///////////////////////////////////

jQuery('.drop_up_menu').click(function() {
	jQuery(this).parent().prev().slideToggle('fast');
	return false;
	});
	
///////////////////////////////////
////// toggles next and hides this
///////////////////////////////////

jQuery('.toggle_next_hide_this').click(function() {
	jQuery(this).css("display","none");
	jQuery(this).next().slideToggle("fast");
	return false;
	});

jQuery('.show_next_hide_this').click(function() {
	jQuery(this).css("display","none");
	jQuery(this).next().css("display","block");
	return false;
	});




///////////////////////////////////
////// updates a form action
///// used in the quotes and orders view where bulk items can be exported or printed
///////////////////////////////////

jQuery('.update_form_action').click(function() {
	
	// update the form action
	jQuery("#bulk_print_download_action").val( jQuery(this).attr("action") );
	
	
	return true;
	
	}); //end update form action







// mobile detect
if( navigator.platform.indexOf("iPhone") != -1 || navigator.platform.indexOf("iPad") != -1 || navigator.platform.indexOf("iPod") != -1 || navigator.userAgent.toLowerCase().indexOf("android") != -1 )
//if(1)
	{
	//alert('1');
	jQuery('#admin_toolbar').css('position','static');
	jQuery('#admin_toolbar_mobile_fix').css('margin-top','469px');
	jQuery('#header_menu_container').css('position','absolute');
	jQuery('#header_menu_container').css('left','0');
	jQuery('#header_menu_container').css('top','0');
	jQuery('.main_2012').css('position','static');
	jQuery('.main_2012').css('margin-left','162px');
	
	}




}); //end doc ready









