/**
* Binds hover events for showcase
*/
function bindHover(){
	$(".showcase li").mouseover(function(){
		//$(this).find('.description').animate( { width:"450px" }, { queue:false, duration:300 } );
		$(this).find('.title').animate( { opacity:"0.8" }, { queue:false, duration:300 } );
	}).mouseout(function(){
		//$(this).find('.description').animate( { width:"0px" }, { queue:false, duration:300 } );
		$(this).find('.title').animate( { opacity:"0" }, { queue:false, duration:300 } );
	});

	$(".showcase-grid li").mouseover(function(){
		//$(this).find('.description').animate( { width:"450px" }, { queue:false, duration:300 } );
		$(this).find('.title').animate( { opacity:"0.8" }, { queue:false, duration:300 } );
	}).mouseout(function(){
		//$(this).find('.description').animate( { width:"0px" }, { queue:false, duration:300 } );
		$(this).find('.title').animate( { opacity:"0" }, { queue:false, duration:300 } );
	});
};

/**
*	Switches to grid display
*/
function switchGrid(){
	$("#showcase-container").fadeOut("fast", function() {
		$(this).fadeIn("fast").removeClass().addClass("showcase-grid");
	});

	// remove mouse events over title
	//$(".showcase li").unbind();

	// set cookie
	$.cookie("view", "grid", {path: '/', expires: 7});

	// set bg position
	$("#grid-view").css('background-position', '0 -300px');
	$("#list-view").css('background-position', '0 -75px');

	// unbind mouse out
	$("#grid-view").unbind("mouseout");

	// set mouseout
	$("#list-view").mouseout(function(){
		$(this).css('background-position', '0 -75px');
	});
};

/**
*	Switches to list display
*/
function switchList(){
	$("#showcase-container").fadeOut("fast", function() {
		$(this).fadeIn("fast").removeClass().addClass("showcase");
	});

	// bind mouse events over title
	//bindHover();

	// set cookie
	$.cookie("view", "list", {path: '/', expires: 7});

	// set bg position
	$("#grid-view").css('background-position', '0 -225px');
	$("#list-view").css('background-position', '0 -150px');

	// unbind mouse out
	$("#list-view").unbind("mouseout");

	// rebind mouseout
	$("#grid-view").mouseout(function(){
		$(this).css('background-position', '0 -225px');
	});
};

function initView(){
	$("#grid-view").mouseover(function(event){
		$(this).css('background-position', '0 -300px');
	});
	$("#grid-view").mouseout(function(){
		$(this).css('background-position', '0 -225px');
	});

	$("#list-view").mouseover(function(event){
		$(this).css('background-position', '0 -150px');
	});
	$("#list-view").mouseout(function(){
		$(this).css('background-position', '0 -75px');
	});

	// read cookie
	if($.cookie("view") == "list"){
		switchList();
	}
	else{
		switchGrid();
	}
};

$(document).ready(function(){
	// bind mouse over events
	bindHover();

	// hide search box
	$("#search").hide();
});

$("#grid-view").live('click', switchGrid);
$("#list-view").live('click', switchList);
$(".search").live('click', function(){ $("#search").slideToggle(300); });

