/************************************
**  Skimbee Studios Javascript
**	@author: Rocco Augusto
**	@url: http://www.skimbee.com
************************************/

$(function()
{		
	//prevent animations and theme selection when the 'select' box is focused
	$('select').focus(function() { $(this).addClass('focus'); }).blur(function() { $(this).removeClass('focus') });
	
	//run css fix on window resize
	$(window).bind('resize', function() { init(w); });
	
	//change themes
	$('.themes a:eq(0)').addClass('selected');
	$('.themes a').click(function()
	{
		var id = $(this).parent('li').attr('class');
		
		$('body').attr('id', id);
		$('.themes a').removeClass('selected');
		$(this).addClass('selected');
	});
	
	//change theme on keypress
	$(document).keydown(function(e)
	{
		//alert(e.which);
		if(e.which == 38 && $('select').attr('class') != 'focus')
		{
			if($('.themes a.selected').parent('li').attr('class') == 'orange') 
			{
				var id = $('.themes li:first-child a').attr('class');
				
				$('body').attr('id', id);
				$('.themes a.selected').removeClass('selected');
				$('.themes li:first-child a').addClass('selected');
			} else {
				var id = $('.themes a.selected').parent('li').next('li').attr('class');
				
				$('body').attr('id', id);
				$('.themes a.selected').removeClass('selected').parent('li').next('li').children('a').addClass('selected');
			}
		}
		
		if(e.which == 40 && $('select').attr('class') != 'focus')
		{
			if($('.themes a.selected').parent('li').attr('class') == 'green') 
			{
				var id = 'orange';
				
				$('body').attr('id', id);
				$('.themes a.selected').removeClass('selected');
				$('.themes li:last-child a').addClass('selected');
			} else {
				var id = $('.themes a.selected').parent('li').prev('li').attr('class');
				
				$('body').attr('id', id);
				$('.themes a.selected').removeClass('selected').parent('li').prev('li').children('a').addClass('selected');
			}
		}
	});
	
	//Destroy hopes and dreams if using IE6
	if($.browser.msie && $.browser.version < 7)
		$('body').prepend('<div class="fail"><h1>Browser Fail :(</h1><p>Sorry but you are using a browser that is not supported by this site. Please upgrade your browser to a more standards compliant, and safer to use browser, such as <a href="http://www.microsoft.com/windows/products/winfamily/ie/default.mspx" target="_blank">Internet Explorer 7</a>, <a href="http://www.getfirefox.com" target="_blank">Firefox 3</a> or <a href="" target="_blank">Google Chrome</a></div>');
	
	//run initial screen testing
	init();
	
	//preload images
	$.preloadCssImages();
});