$(document).ready(function() {
	
	// Loop thru nav and set active state
	$("ul#main_nav li a.active").each(function(){
			var htmlStr = $(this).html();
			$(this).html('+ '+htmlStr);
			$(this).attr('title', '+ '+htmlStr);
		});
	
	// Loop thumb
	$("a[rel=thumb]'").live('click', function() {
			var id = $(this).attr('id').replace('thumb_','');
			var arr=$(this).attr('title').split(", ");
			var client = arr[0];
			var type = arr[1];
			changeImage(id,client,type);
			return false;
	});
	
	$("div#large_image a").each(function(){
	   $(this).fadeOut(0);
	});
	$("div#large_image a#img_1").fadeIn(0);
	
	if(window.opera) {
		if ($("a.jqbookmark").attr("rel") != ""){
			$("a.jqbookmark").attr("rel","sidebar");
		} 
	}
	$("a.jqbookmark").click(function(event){
		event.preventDefault();
		var url = this.href;
		var title = this.title;
		if (window.sidebar) { // Mozilla Firefox Bookmark
			window.sidebar.addPanel(title, url,"");
		} else if( window.external ) { // IE Favorite
			window.external.AddFavorite( url, title);
		} else if(window.opera) { // Opera 7+
			return false; // do nothing
		} else { 
			 alert('Unfortunately, this browser does not support the requested action,'
			 + ' please bookmark this page manually.');
		}
	});
	
});

function bigImageClick(id){
	var arr=$('a#img_'+id).attr('title').split(", ");
	var client = arr[0];
	var type = arr[1];
	changeImage(id,client,type);
}

function changeImage(id,client,type){
	//Fade out image
	$("div#large_image a").each(function(){
	    var display = $(this).css('display');
		if(display!='none'){current = $(this).attr('id').replace('img_','');}
	});
	if(current!=id){
		//Fade in image
		$("#img_"+current).fadeOut('slow');
		//Fade in image
		$("#img_"+id).fadeIn('slow');
	}
	//Update client
	$("#client").html(client+'<span>'+type+'</span><span class="green">+</span>');
	//Remove class
	$('#thumbs td a').removeClass('active');
	//Add class
	$('a#thumb_'+id).addClass('active');
}
				
