$(document).ready(function() {
	
	$(function() {
		var newHash      = "",
			$mainContent = $("#main-content"),
			baseHeight   = 0,
			$el;
	
		$("#pageWrap").delegate("a", "click", function() {
		    if (!$(this).is('.defaultClick')) {
		        window.location.hash = $(this).attr("href");
			    return false;
			};
		});
		
		$(window).bind('hashchange', function(){
			newHash = window.location.hash.substring(1);
			//alert (window.location.hash);
			if (newHash) {
				$mainContent.find("#guts").fadeOut(200, function() {
						$mainContent.hide().load(newHash + " #guts", function() {
							
								if (window.location.hash == "#products/?1"){
								$('#coda-slider-1').codaSlider({firstPanelToLoad: 1});
							};
								
							if (window.location.hash == "#products/?2"){
								$('#coda-slider-1').codaSlider({firstPanelToLoad: 2});
							};
							if (window.location.hash == "#products/?3"){
								$('#coda-slider-1').codaSlider({firstPanelToLoad: 3});
								$('#iframeLoader').html('<iframe  width="270" height="315" frameborder="0" src="eos.html" scrolling="no"></iframe>');
							};
							if (window.location.hash == "#products/?4"){
								$('#coda-slider-1').codaSlider({firstPanelToLoad: 4});
							};
							$("div.button").click(function(){
				
							$clicked = $(this);
							// if the button is not already "transformed" AND is not animated
							if ($clicked.css("background-position") != "bottom left") {
								
								$clicked.css({
									'background-position' : 'bottom left',
									'color' : '#000'
								});
								
								// each button div MUST have a "xx-button" and the target div must have an id "xx" 
								var idToLoad = $clicked.attr("id").split('-');
								
								//we search trough the content for the visible div and we fade it out
								$(".slider-content").find("div:visible").fadeOut("fast", function(){
									//once the fade out is completed, we start to fade in the right div
									$(this).parent().find("#"+idToLoad[0]).fadeIn();
								})
							} //end products page div changing function
							
							//we reset the other buttons to default style
							$clicked.siblings(".button").css({
								'background-position' : 'top left'
							});
						});
								// animate height of content
								$("#content").animate({
										height: baseHeight + $mainContent.height() + "px"
								}); $mainContent.fadeIn(200);

						   //highlight current nav element
							$("#nav a").removeClass("current");
							$("#nav a[href="+newHash+"]").addClass("current");
							 $(function() {
    var path = window.location.hash;
    if(path.match('#products.php'))
	
    {
    $("#productsClick").addClass("current");
    }

});
						});
				 });
				 
			}; //end if newhash        
		}); //end hashchange
		$(window).trigger('hashchange');
		
	}); // end page changing function
}); //end doc.ready

