// JavaScript Document

//Product Gallery =========================================================

$(function() {
$(".image").click(function() {
var image = $(this).attr("rel");
$('#image').hide();
$('#image').fadeIn('slow');
$('#image').html('<img src="' + image + '"/>');
return false;
	});
});

//Slider Hide Effect =========================================================

jQuery(document).ready(function() {
  jQuery(".dealersContent").hide();
  //toggle the componenet with class msg_body
  jQuery(".dealersHeading").click(function()
  {
    jQuery(this).next(".dealersContent").slideToggle(500);
  });
});

jQuery(document).ready(function() {
	jQuery(".homeContent").hide(500);
  jQuery(this).next(".homeContent_first").slideToggle(500);
  //toggle the componenet with class msg_body
  jQuery(".homeHeading").click(function()
  {
	 jQuery(".homeContent").hide(500);
	 jQuery(".homeContent_first").hide(500);
    jQuery(this).next(".homeContent").slideToggle(500);
  });
  
   jQuery(".homeHeading_first").click(function()
  {
	 jQuery(".homeContent").hide(500);
    jQuery(this).next(".homeContent_first").slideToggle(500);
  });
  
});

jQuery(document).ready(function() {
  jQuery(".checkoutContent").hide();
  //toggle the componenet with class msg_body
  jQuery(".checkoutTitle").click(function()
  {
    jQuery(this).next(".checkoutContent").slideToggle(500);
  });
});

//Color Box =========================================================

 $(document).ready(function(){
				//Examples of Global Changes
				$.fn.colorbox.settings.bgOpacity = "0.9";
				$.fn.colorbox.settings.contentCurrent = "{current} / {total}";

				//Examples of how to assign the ColorBox event to elements.
				
				$(".colorbox").colorbox({transition:"elastic"});
					});

jQuery.fn.fadeToggle = function(speed, easing, callback) {
  return this.animate({opacity: 'toggle'}, speed, easing, callback);  
};

$(document).ready(function() {
	$('.productContact').hide();
  	$('a.mail, .productContact a.close').click(function() {
    $(".productContact").fadeToggle('slow');
  });
  
});

//Searform =========================================================

var DEF_VAL   = "Search"; // Default Value
var isSafari = (navigator.userAgent.indexOf("AppleWebKit") !=-1);
// Detecting not only Safari but WebKit-based browsers

run();
function run()
{
    var oldOnload = window.onload; // window.onload will be overwritten, so save the old value
    if (typeof(window.onload) != "function") {
        window.onload = init;
    } else {
        window.onload = function() {
            oldOnload();
            init();
        }
    }
}

function init() {
    if (!document.getElementById) return;
    var theSearchField = document.getElementById('search');
    if (isSafari) {
        // Changing type to 'search' from 'text'
        // and inserting 'autosave,' 'results,' 'placeholder' values for Safari and WebKit-based browsers
        theSearchField.setAttribute('type', 'search');
        theSearchField.setAttribute('autosave', 'saved.data');
        theSearchField.setAttribute('results', '5');
        theSearchField.setAttribute('placeholder', DEF_VAL);
    } else {
        // Doing the 'Live Search'-displaying-&-hiding-stuff for non-WebKit-based browsers
        theSearchField.onfocus    = focusSearch;
        theSearchField.onblur     = blurSearch;
        if (theSearchField.value=='') theSearchField.value = DEF_VAL;
    }
}

function focusSearch() {
    if (this.value==DEF_VAL) {
        this.value = '';
    }
}

function blurSearch() {
    if (this.value=='') {
        this.value = DEF_VAL;
    }
}

//Bad Browser =========================================================

function badBrowser(){
	if($.browser.msie && parseInt($.browser.version) <= 7){ return true;}
	
	return false;
}

function getBadBrowser(c_name)
{
	if (document.cookie.length>0)
	{
	c_start=document.cookie.indexOf(c_name + "=");
	if (c_start!=-1)
		{ 
		c_start=c_start + c_name.length+1; 
		c_end=document.cookie.indexOf(";",c_start);
		if (c_end==-1) c_end=document.cookie.length;
		return unescape(document.cookie.substring(c_start,c_end));
		} 
	}
	return "";
}	

function setBadBrowser(c_name,value,expiredays)
{
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value) + ((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

if(badBrowser() && getBadBrowser('browserWarning') != 'seen' ){
	$(function(){
		$("<div id='browserWarning'>You are using an unsafe and outdated browser. You should consider upgrading to <a href='http://www.google.com/chrome'>Google Chrome</a> or <a href='http://getfirefox.com'>FireFox</a>. These updated and secure browsers are free! [<a href='#' id='warningClose'>Close</a>] </div> ")
			.css({
				backgroundColor: '#fcfdde',
				'width': '100%',
				'border-top': 'solid 1px #000',
				'border-bottom': 'solid 1px #000',
				'text-align': 'center',
				padding:'5px 0px 5px 0px',
				'margin-top':'-26px'
			})
			.prependTo("body");
		
		$('#warningClose').click(function(){
			setBadBrowser('browserWarning','seen');
			$('#browserWarning').slideUp('slow');
			return false;
		});
	});	
}

//Slider =========================================================

(function($) {

	$.fn.easySlider = function(options){
	  
		// default configuration properties
		var defaults = {			
			prevId: 		'prevBtn',
			prevText: 		'&lt;&lt;Previous',
			nextId: 		'nextBtn',	
			nextText: 		'Next&gt;&gt;',
			controlsShow:	true,
			controlsBefore:	'',
			controlsAfter:	'',	
			controlsFade:	true,
			firstId: 		'firstBtn',
			firstText: 		'First',
			firstShow:		false,
			lastId: 		'lastBtn',	
			lastText: 		'Last',
			lastShow:		false,				
			vertical:		false,
			speed: 			800,
			auto:			false,
			pause:			5000,
			continuous:		false
		}; 
		
		var options = $.extend(defaults, options);  
				
		this.each(function() {  
			var obj = $(this); 				
			var s = $("li", obj).length;
			var w = $("li", obj).width(); 
			var h = $("li", obj).height(); 
			obj.width(w); 
			obj.height(h); 
			obj.css("overflow","hidden");
			var ts = s-1;
			var t = 0;
			$("ul", obj).css('width',s*w);			
			if(!options.vertical) $("li", obj).css('float','left');
			
			if(options.controlsShow){
				var html = options.controlsBefore;
				if(options.firstShow) html += '<span id="'+ options.firstId +'"><a href=\"javascript:void(0);\">'+ options.firstText +'</a></span>';
				html += ' <span id="'+ options.prevId +'"><a href=\"javascript:void(0);\">'+ options.prevText +'</a></span>';
				html += ' <span id="'+ options.nextId +'"><a href=\"javascript:void(0);\">'+ options.nextText +'</a></span>';
				if(options.lastShow) html += ' <span id="'+ options.lastId +'"><a href=\"javascript:void(0);\">'+ options.lastText +'</a></span>';
				html += options.controlsAfter;						
				$(obj).after(html);										
			};
	
			$("a","#"+options.nextId).click(function(){		
				animate("next",true);
			});
			$("a","#"+options.prevId).click(function(){		
				animate("prev",true);				
			});	
			$("a","#"+options.firstId).click(function(){		
				animate("first",true);
			});				
			$("a","#"+options.lastId).click(function(){		
				animate("last",true);				
			});		
			
			function animate(dir,clicked){
				var ot = t;				
				switch(dir){
					case "next":
						t = (ot>=ts) ? (options.continuous ? 0 : ts) : t+1;						
						break; 
					case "prev":
						t = (t<=0) ? (options.continuous ? ts : 0) : t-1;
						break; 
					case "first":
						t = 0;
						break; 
					case "last":
						t = ts;
						break; 
					default:
						break; 
				};	
				
				var diff = Math.abs(ot-t);
				var speed = diff*options.speed;						
				if(!options.vertical) {
					p = (t*w*-1);
					$("ul",obj).animate(
						{ marginLeft: p }, 
						speed
					);				
				} else {
					p = (t*h*-1);
					$("ul",obj).animate(
						{ marginTop: p }, 
						speed
					);					
				};
				
				if(!options.continuous && options.controlsFade){					
					if(t==ts){
						$("a","#"+options.nextId).hide();
						$("a","#"+options.lastId).hide();
					} else {
						$("a","#"+options.nextId).show();
						$("a","#"+options.lastId).show();					
					};
					if(t==0){
						$("a","#"+options.prevId).hide();
						$("a","#"+options.firstId).hide();
					} else {
						$("a","#"+options.prevId).show();
						$("a","#"+options.firstId).show();
					};					
				};				
				
				if(clicked) clearTimeout(timeout);
				if(options.auto && dir=="next" && !clicked){;
					timeout = setTimeout(function(){
						animate("next",false);
					},diff*options.speed+options.pause);
				};
				
			};
			// init
			var timeout;
			if(options.auto){;
				timeout = setTimeout(function(){
					animate("next",false);
				},options.pause);
			};		
		
			if(!options.continuous && options.controlsFade){					
				$("a","#"+options.prevId).hide();
				$("a","#"+options.firstId).hide();				
			};				
			
		});
	  
	};

})(jQuery);

