$(function() {
	
	//stylesheet switcher
	$('.styleswitch').click(function()
	{
		switchStylestyle(this.getAttribute("rel"));
		return false;
	});
	var c = readCookie('style');
	if (c) switchStylestyle(c);
	
	
	//coda slider
	jQuery("div#slider1").codaSlider()
	
	//featured image view project slide on hover
	$('.featured_images').hover(function()	{
			$(this).find('.viewproject').slideDown(100);
	},
	//onmouseout
	function()	{
			$(this).find('.viewproject').slideUp(150);}
	);
	//portfolio images view project slide on hover
	$('.portfolio_img').hover(function()	{
			$(this).find('.viewproject2').slideDown(100);
	},
	//onmouseout
	function()	{
			$(this).find('.viewproject2').slideUp(150);}
	);
	
	//hover popups theme for buttons
	//set alt tags to empty
	$('#theme_container img').attr('alt', "");
	$('#theme_container a').hover(function(e) {
		var html = '<div id="themehover">';
		html += $(this).attr('name') + ' Theme';
		html += '</div>';
		
		$('body').append(html).children('#themehover').hide().fadeIn(200);
		$('#themehover').css('top', e.pageY + 15).css('left', e.pageX + 15);
		
	}, function() {
		//mouse out
		$('#themehover').remove();
	
	});
	
	$('#theme_container a').mousemove(function(e) {
		$('#themehover').css('top', e.pageY + 15).css('left', e.pageX + 15);
	});
	
});

//Stylesheet switcher functions
function switchStylestyle(styleName)
{
	$('link[@rel*=style][title]').each(function(i) 
	{
		this.disabled = true;
		if (this.getAttribute('title') == styleName) this.disabled = false;
	});
	createCookie('style', styleName, 365);
}

function createCookie(name,value,days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
function eraseCookie(name)
{
	createCookie(name,"",-1);
}
