$(document).ready(function(){
	
lastBlock='dummy';
//location URI marker
	if( window.location.pathname.match('/theexperience') ){ locationElement('#theexperience'); 	lastBlock=$('#theexperience');}
	if( window.location.pathname.match('/whatwedo') ){ locationElement('#whatwedo'); lastBlock=$('#whatwedo');}
	if( window.location.pathname.match('/whoweare') ){ $('#whoWeAreImg').addClass('whoWeAreHover');}
	if( window.location.pathname.match('/contact') ){ $('#contactImg').addClass('contactHover');}

	
	$.each($("#topNav ul li a"),
	function(){
	if( window.location.pathname == $(this).attr('href') ){
															$(this).css({"color":"orange"});
															}
				}
			);
//click action
$("#topNav ul li a").click(
				    function(){
							victim = $(this).parent();
							if( lastBlock === 'dummy'){
								openElement( victim );
								lastBlock = victim ;
							} else {
										if( lastBlock == victim ){
											closeElement(lastBlock);
											lastBlock ='dummy';
										} else {
											closeElement(lastBlock);
											openElement(victim);
											lastBlock = victim;								
										}
									}
						      }
						);
						
//---- functions--------
//triggers open position for the location URI
function locationElement(theElement){
	openElement(theElement);
	lastBlock = theElement;
	}

//Opens the specified element
function openElement(theElement){
	maxWidth = $("div",theElement).width() + $("img",theElement).width();	
		$('div',theElement).css({"visibility":"visible"});
		$(theElement).animate({width: maxWidth + "px"}, { queue:false, duration:400}); //open
	//Activate
	if( $("a img", theElement).css("background-position-x").length > 0){
			bgPositionX = $("a img", theElement).css("background-position-x");//ie solution
			$("a img", theElement).css({"background-position-x": bgPositionX});
			$("a img", theElement).css({"background-position-y": "0px"});
	} else {
			bgPosition = $("a img", theElement).css("background-position");
			xy = bgPosition.split(' ');											//firefox solution
			$("a img", theElement).css({"background-position": xy[0] + " 0px"});
	} 
}
 
//closes the specified element
function closeElement(theElement){
		minWidth = $("img",theElement).width();	
	  	$('div',theElement).css({"visibility":"hidden"});
		$(theElement).animate({width: minWidth + "px"}, { queue:false, duration:400 }); //close
	//Deactivate
	if( $("a img", theElement).css("background-position-x").length > 0){
				bgPositionX = $("a img", theElement).css("background-position-x");//ie solution
				$("a img", theElement).css({"background-position-x": bgPositionX });	
				$("a img", theElement).css({"background-position-y": "61px"});
		} else {
				bgPosition = $("a img", theElement).css("background-position");
				xy = bgPosition.split(' ');											//firefox solution
				$("a img", theElement).css({"background-position": xy[0] + " 61px"});
		}
	}
});