$(document).ready(function(){ 
			
	// homepage transistions
	
	if ($.browser.msie && $.browser.version < 7) {
		
		//$('#home_1#home_2, #home_3, #home_4').hide();
		$('#home_2, #home_3, #home_4').hide();
		
		$('.transition a').click(function() {
									   
			var rel = $(this).attr('rel');
			
			$('#chooser a').removeClass('chosen');
			$('#thumb_' + rel).addClass('chosen');
			$('.home_image').hide();
			$('#home_' + rel).show();
			
			return false;
			
		});
		
	} else {
		
		//$('#home_1, #home_2, #home_3, #home_4').css('opacity', '0');
		$('#home_2, #home_3, #home_4').css('opacity', '1');
		$('#home_2, #home_3, #home_4').hide();
		$('.transition a').click(function() {
									   
			var rel = $(this).attr('rel');
			
			$('#chooser a').removeClass('chosen');
			$('#thumb_' + rel).addClass('chosen');
			$('.home_image').stop().fadeTo(300, 0);
			$('.home_image').hide();
			$('#home_' + rel).show();
			$('#home_' + rel).stop().fadeTo(300, 1);
			

			
			return false;
			
		});
	
	}
	
	// client page transisitions
	
	// $('#image_chooser a span').css('opacity', '0');
	
	$('#image_chooser a').click(function() {
										 
		$('#image_holder img:first').stop().fadeTo(300, 0);
		
		$('#image_chooser a').removeClass('chosen');
		$(this).addClass('chosen');
		$('#image_chooser a span').stop().fadeOut(300);
		$(this).children('span').stop().fadeIn(300);
		
		return false;
		
	});
	
	// client page text panel
	
//	$('#text_panel_handle').addClass("open");
//	
//	$('#text_panel_handle').toggle(function() {
//		
//		$(this).removeClass("open");
//		$(this).addClass("closed");
//		$('#text_panel').hide();
//		
//		// set cookie:text_panel = hide
//		$.cookie("text_panel", "hide");
//	},
//	function() {
//	
//		$(this).removeClass("closed");
//		$(this).addClass("open");
//		
//		// set cookie:text_panel = show
//		$.cookie("text_panel","show");
//		
//		//$('#text_panel').animate({"width": "0"}, 500, "swing");
//		$('#text_panel').show();
//	
//	});



// var button = $('#text_panel_handle');
//
//    //check the cookie when the page loads
//    if ($.cookie('text_panel') === 'hide') {
//        togglePanel(button, false);
//    }
//    else {
//        togglePanel(button, true);
//    }
//
//    //handle the clicking of the show/hide toggle button
//    button.click(function() {
//        //toggle the panel as required, base on current state
//        if (button.text() === "SHOW") {
//            togglePanel($(this), true);
//        }
//        else {
//            togglePanel($(this), false);
//        }
//    });
//
//
//function togglePanel(button, show) {
//
//    var panel = $('#text_panel_handle');
//
//    if (show) {
//        panel.removeClass('open');
//		panel.addClass('closed');
//        button.text('-Hide');
//        $.cookie('text_panel', '', { path: '/' });
//    }
//    else {
//        panel.removeClass('closed');
//		panel.addClass('open');
//        button.text('+Show');
//        $.cookie('text_panel', 'hide', { path: '/' });
//    }
//}





 var button = 	$('#text_panel_handle');
 var panel = 	$('#text_panel');
 
 
 
 
    if ($.cookie('text_panel') == 'hidden') {
        togglePanel(button, false);
    }
	if ($.cookie('text_panel') == 'show') {
        togglePanel(button, true);
    }
    else {
        togglePanel(button, false);
    }
 
 	button.click(function(){
		if(button.text() == "SHOW"){
			togglePanel($(this),true)
		}else{
			togglePanel($(this),false)	
		}				  
	});
 



	function togglePanel(button, show){
	
		if(show){
			panel.show();
			button.removeClass('closed');
			button.addClass('open');
        	button.text('HIDE');
        	$.cookie('text_panel', 'show', {path: '/'});
		}
		else{
			panel.hide();
			button.removeClass('open');
			button.addClass('closed');
        	button.text('SHOW');
        	$.cookie('text_panel', 'hidden', {path: '/'});	
		}
	
	}
	
	
	

	$("a[rel=external]").each(function() {
    	
		this.target = "_blank";
  	
	});
	
	$("a[rel=external]").click(function() {
	
		pageTracker._trackPageview('/outbound/'+this.href);
		
	});
	
	$(".track").click(function() {
		
		var thumb = $(this).attr('rel');
		pageTracker._trackPageview('/home/'+thumb);
		
	});
	
	$(".brompton_track").click(function() {
		
		var thumb = $(this).attr('rel');
		pageTracker._trackPageview('/brompton/'+thumb);
		
	});
	
});

