/*!
 * Dean Howe
 * http://dea.n-howe.com/
 *
 * Feel free re-use but do so at your own risk ;)
 *
 * Date: Sun April 26 2010
 */


// set up some deep linking using JQuery Address (http://www.asual.com/jquery/address/)
$.address.change(function(event) {  
	// do something depending on the event.value property
	// only refresh the page if we must, ie not on the index page
	if(event.value != '/'){
		// call the site and get some JSON love
		$.post('/api/page/url'+event.value, { url: event.value },
			function(data){
				// set the page Title
				
				if(data.section == 'Main'){show_main_menu()}
				else if(data.section == 'Products'){show_products_menu()}
				
				$.address.title(data.title)
				// set the page Content
				$('#content-body').html(data.content);
				
				// re-assign some deep linkage to the fresh content
				assign_deep_links();
				
		 }, "json");
	}
}); 			
			
// assign the deep links to the anchors, ahoy!
function assign_deep_links(){
	// should I swith to having to declare internals?
	$("a[rel!='external']").click(function() {
		$.address.value($(this).attr("class"));
		return false;
	});
}	
		
function show_main_menu() {
	
	//Load Modules
				if($('li[class$=load-modules Products] span[class$=buttonText]').css('display') == 'block'){
							$('li[class$=load-modules Products] span[class$=buttonText]').hide();
				}
				$('li[class$=load-modules Products]').animate({
						//opacity: 0.25,
						width: 'hide'
					  }, 1100, function() {
							if($('li[class$=load-modules Products] span[class$=buttonText]').css('display') == 'none'){
							$('li[class$=load-modules Products] span[class$=buttonText]').fadeIn();
							}
					  });
					  
				
				//Aero Jack
				if($('li[class$=aero-jack Products] span[class$=buttonText]').css('display') == 'block'){
							$('li[class$=aero-jack Products] span[class$=buttonText]').hide();
				}
				$('li[class$=aero-jack Products]').animate({
						//opacity: 0.25,
						width: 'hide'
					  }, 900, function() {
							if($('li[class$=aero-jack Products] span[class$=buttonText]').css('display') == 'none'){
							$('li[class$=aero-jack Products] span[class$=buttonText]').fadeIn();
							}
							
							//Contacts
							if($('li[class$=contacts Main] span[class$=buttonText]').css('display') == 'block'){
										$('li[class$=contacts Main] span[class$=buttonText]').hide();
							}
							$('li[class$=contacts Main]').delay(300).animate({
									//opacity: 0.25,
									width: 'show'
								  }, 900, function() {
										if($('li[class$=contacts Main] span[class$=buttonText]').css('display') == 'none'){
										$('li[class$=contacts Main] span[class$=buttonText]').fadeIn();
										}
								  });
			
			
							//Hire Info
							if($('li[class$=hire-info Main] span[class$=buttonText]').css('display') == 'block'){
										$('li[class$=hire-info Main] span[class$=buttonText]').hide();
							}
							$('li[class$=hire-info Main]').delay(300).animate({
									//opacity: 0.25,
									width: 'show'
								  }, 700, function() {
										if($('li[class$=hire-info Main] span[class$=buttonText]').css('display') == 'none'){
										$('li[class$=hire-info Main] span[class$=buttonText]').fadeIn();
										}
								  });
							
							
							//Sales Info
							if($('li[class$=sales-info Main] span[class$=buttonText]').css('display') == 'block'){
										$('li[class$=sales-info Main] span[class$=buttonText]').hide();
							}
							$('li[class$=sales-info Main]').delay(300).animate({
									//opacity: 0.25,
									width: 'show'
								  }, 500, function() {
										if($('li[class$=sales-info Main] span[class$=buttonText]').css('display') == 'none'){
										$('li[class$=sales-info Main] span[class$=buttonText]').fadeIn();
										}
								  });
							
					  });
				
				
				//Aero Planks
				if($('li[class$=aero-planks Products] span[class$=buttonText]').css('display') == 'block'){
							$('li[class$=aero-planks Products] span[class$=buttonText]').hide();
				}
				$('li[class$=aero-planks Products]').animate({
						//opacity: 0.25,
						width: 'hide'
					  }, 700, function() {
							if($('li[class$=aero-planks Products] span[class$=buttonText]').css('display') == 'none'){
							$('li[class$=aero-planks Products] span[class$=buttonText]').fadeIn();
							}
					  });
				
				
				//Aero Pallets
				if($('li[class$=aero-pallets Products] span[class$=buttonText]').css('display') == 'block'){
							$('li[class$=aero-pallets Products] span[class$=buttonText]').hide();
				}
				$('li[class$=aero-pallets Products]').animate({
						//opacity: 0.25,
						width: 'hide'
					}, 500, function() {
							if($('li[class$=aero-pallets Products] span[class$=buttonText]').css('display') == 'none'){
							$('li[class$=aero-pallets Products] span[class$=buttonText]').fadeIn();
							}
					});
				
				//$('li[class^=products]').toggleClass('Main');
				return false;
	
}

function show_products_menu() {

	//Contacts
				if($('li[class$=contacts Main] span[class$=buttonText]').css('display') == 'block'){
							$('li[class$=contacts Main] span[class$=buttonText]').hide();
				}
				$('li[class$=contacts Main]').animate({
						//opacity: 0.25,
						width: 'hide'
					  }, 500, function() {
							if($('li[class$=contacts Main] span[class$=buttonText]').css('display') == 'none'){
							$('li[class$=contacts Main] span[class$=buttonText]').fadeIn();
							}
					  });


				//Hire Info
				if($('li[class$=hire-info Main] span[class$=buttonText]').css('display') == 'block'){
							$('li[class$=hire-info Main] span[class$=buttonText]').hide();
				}
				$('li[class$=hire-info Main]').animate({
						//opacity: 0.25,
						width: 'hide'
					  }, 700, function() {
							if($('li[class$=hire-info Main] span[class$=buttonText]').css('display') == 'none'){
							$('li[class$=hire-info Main] span[class$=buttonText]').fadeIn();
							}
					  });
				
				
				//Sales Info
				if($('li[class$=sales-info Main] span[class$=buttonText]').css('display') == 'block'){
							$('li[class$=sales-info Main] span[class$=buttonText]').hide();
				}
				$('li[class$=sales-info Main]').animate({
						//opacity: 0.25,
						width: 'hide'
					  }, 900, function() {
							if($('li[class$=sales-info Main] span[class$=buttonText]').css('display') == 'none'){
							$('li[class$=sales-info Main] span[class$=buttonText]').fadeIn();
							}
					 
								
				
								//Load Modules
								if($('li[class$=load-modules Products] span[class$=buttonText]').css('display') == 'block'){
											$('li[class$=load-modules Products] span[class$=buttonText]').hide();
								}
								$('li[class$=load-modules Products]').delay(300).animate({
										//opacity: 0.25,
										width: 'show'
									  }, 500, function() {
											if($('li[class$=load-modules Products] span[class$=buttonText]').css('display') == 'none'){
											$('li[class$=load-modules Products] span[class$=buttonText]').fadeIn();
											}
									  });
									  
								
								//Aero Jack
								if($('li[class$=aero-jack Products] span[class$=buttonText]').css('display') == 'block'){
											$('li[class$=aero-jack Products] span[class$=buttonText]').hide();
								}
								$('li[class$=aero-jack Products]').delay(300).animate({
										//opacity: 0.25,
										width: 'show'
									  }, 700, function() {
											if($('li[class$=aero-jack Products] span[class$=buttonText]').css('display') == 'none'){
											$('li[class$=aero-jack Products] span[class$=buttonText]').fadeIn();
											}
									  });
								
								
								//Aero Planks
								if($('li[class$=aero-planks Products] span[class$=buttonText]').css('display') == 'block'){
											$('li[class$=aero-planks Products] span[class$=buttonText]').hide();
								}
								$('li[class$=aero-planks Products]').delay(300).animate({
										//opacity: 0.25,
										width: 'show'
									  }, 900, function() {
											if($('li[class$=aero-planks Products] span[class$=buttonText]').css('display') == 'none'){
											$('li[class$=aero-planks Products] span[class$=buttonText]').fadeIn();
											}
									  });
								
								
								//Aero Pallets
								if($('li[class$=aero-pallets Products] span[class$=buttonText]').css('display') == 'block'){
											$('li[class$=aero-pallets Products] span[class$=buttonText]').hide();
								}
								$('li[class$=aero-pallets Products]').delay(300).animate({
										//opacity: 0.25,
										width: 'show'
									  }, 1100, function() {
											if($('li[class$=aero-pallets Products] span[class$=buttonText]').css('display') == 'none'){
											$('li[class$=aero-pallets Products] span[class$=buttonText]').fadeIn();
											}
									  });
								
								
								//$('li[class^=products]').toggleClass('Main');
								return false;
						 });

}


$(document).ready(function() {

/*
*   trigger the cascade
*/

assign_deep_links();


/*$('div#navigation a').click(function(){
	
	$('div#navigation li').removeClass('Selected');
	$('div#navigation li[class^='+$(this).attr("class")+']').addClass('Selected');
	return false;
});
*/
	
	
	
	$('li[class$=Products], li[class$=Products] span[class$=buttonText]').hide();
	//$('li[class$=load-modules Products] span[class$=buttonText]').css('display', 'none');
	
	
	$('a[class=welcome]').click(function() {
		show_main_menu();
		//$('li[class^=products]').toggleClass('Main');
		//$('li[class$=Main]').hide();
	});
	
	//Products Menu Animation
	$('a[class=products]').click(function() {
		 show_products_menu();
		 //$('li[class^=products]').toggleClass('Main');
		//$('li[class$=Main]').hide();
	});
});