$.fn.initSpecial = function(settings) {
	return this.each(function(){		
		var slider = $(this);							
		$('#control li').each(function(z) {
			$(this).hover(function() {
                slider.find("div").css("display", "none");
                $("#control li").removeClass("hover");
                $("#control li").find("img").show();				
				var special = $(this).attr("id");
				$(this).addClass("hover");
				$("." + special).css("display", "block");
				$(this).find("img").hide();
				return false;
			});
		});
	});
}; 



$(document).ready(function(){
	var cssDummy = {
		init: function(){
			$('<div id="dummy-element" style="display:none" />').appendTo('body');
		},
		check: function(callback) {
			if($('#dummy-element').width()==2) callback();
			else setTimeout(function(){cssDummy.check(callback)}, 200);
		}
	}
	cssDummy.init();
	
	$("a.switch").each(function(z) {
		$(this).click(function() {
			obj = $(this).attr('rel');
			
			$('body').append('<div id="loader" />');
			
			$('#loader').css({
					background: 'black url(images/loading.gif) center center no-repeat',
					display: 'none',
					position: 'absolute',
					top:0, left: 0,
					zIndex: 1000,
					width: '100%',
					height: '100%'
				})
				.fadeIn(750,function(){
					$("#stylesheet").attr("href",obj);
					$.cookie("css",obj, {expires: 365, path: '/'});
					
					$("#styles").hide();
					
					window.setTimeout(function(){cssDummy.check(function(){
						$('#loader').fadeOut(750);	
					})}, 1500);;
				});
		});
	});
	
	$("#toggle img").click(function () {
		if($("#styles").is(":hidden")) {
			$("#styles").slideDown({duration: 1000});
		} else {
			$("#styles").slideUp({duration: 1500});
		}
	});
	
	/* $(".boxswitcher").click(function () {
		//subject = $(this).parent().parent().children().children("ul");
		subject = $(".testor");
		
		if(subject.is(":hidden")) {
			subject.slideDown({duration: 1000, easing: 'easeOutBounce'});
			
			$(this).css("background-position","top");
		} else {
			subject.slideUp({duration: 1500, easing: 'easeOutBounce'});

			$(this).css("background-position","bottom");
		}
	}); */
	
	$('#special').initSpecial();
});
