jQuery(document).ready(function($) {
	var templateurl = jQuery('#templateurl').attr('href') + "/";
    
	
	/**************COLOR***************/
	jQuery('#style-switcher a.color-box').each(function (i) {
		var a = jQuery(this);
		a.css({
			backgroundColor: '#' + a.attr('rel')
		})
	})    
	
   	var switcher_skins = jQuery('#style-switcher a.color-box');
   	var switcher_link = jQuery('#skins-switcher');
	
	var color = jQuery.cookie("ts_cookie_color");
	if(color){
		if (color == "0e76b8") {
			switcher_link.attr('href',templateurl+"styles/blue/style.css");
			var atrrHref = switcher_link.attr('href');
			jQuery("#logoimg img").attr('src', templateurl+"styles/blue/logo.png");
		}else if (color == "000000") {
			switcher_link.attr('href',templateurl+"styles/black/style.css");
			var atrrHref = switcher_link.attr('href');
			jQuery("#logoimg img").attr('src', templateurl+"styles/black/logo.png");
		}else if (color == "5b8b23") {
			switcher_link.attr('href',templateurl+"styles/green/style.css");
			var atrrHref = switcher_link.attr('href');
			jQuery("#logoimg img").attr('src', templateurl+"styles/green/logo.png");
		}else if (color == "b31616") {
			switcher_link.attr('href',templateurl+"styles/red/style.css");
			var atrrHref = switcher_link.attr('href');
			jQuery("#logoimg img").attr('src', templateurl+"styles/red/logo.png");
		}else if (color == "f5b81c") {
			switcher_link.attr('href',templateurl+"styles/yellow/style.css");
			var atrrHref = switcher_link.attr('href');
			jQuery("#logoimg img").attr('src', templateurl+"styles/yellow/logo.png");
		}
		jQuery('body').css({
			backgroundColor: '#' + color
		});
		Cufon.refresh();
	}
   
      
   switcher_skins.click(function(e) {
    var color = jQuery(this).attr('rel');
    var skins;
    
    if (color == "0e76b8") {
      switcher_link.attr('href',templateurl+"styles/blue/style.css");
      var atrrHref = switcher_link.attr('href');
	  jQuery("#logoimg img").attr('src',templateurl+"styles/blue/logo.png");
	  jQuery("#topnav li a.current").css({
			"color" : "#"+color						 
	  });
    }
    if(color == "000000") {
      switcher_link.attr('href',templateurl+"styles/black/style.css");
      var atrrHref = switcher_link.attr('href');
	  jQuery("#logoimg img").attr('src',templateurl+"styles/black/logo.png");
	  jQuery("#topnav li a.current").css({
			"color" : "#"+color				 
	  });
    }
    if(color == "5b8b23") {
      switcher_link.attr('href',templateurl+"styles/green/style.css")
      var atrrHref = switcher_link.attr('href');
	  jQuery("#logoimg img").attr('src',templateurl+"styles/green/logo.png");
	  jQuery("#topnav li a.current").css({
			"color" : "#"+color					 
	  });
    }
    if(color == "b31616") {
      switcher_link.attr('href', templateurl+"styles/red/style.css");
      var atrrHref = switcher_link.attr('href');
	  jQuery("#logoimg img").attr('src',templateurl+"styles/red/logo.png");
	  jQuery("#topnav li a.current").css({
			"color" : "#"+color					 
	  });
    }
    if(color == "f5b81c") {
      switcher_link.attr('href', templateurl+"styles/yellow/style.css");
      var atrrHref = switcher_link.attr('href');
	  jQuery("#logoimg img").attr('src', templateurl+"styles/yellow/logo.png");
	  jQuery("#topnav li a.current").css({
			"color" : "#"+color
	  });
    }
	Cufon.refresh();

    jQuery.cookie("ts_cookie_color", color);  
	
    return false;
   });  
   
   /* Background */
  jQuery('#style-switcher a.bg-box').each(function (i) {
    var backgroundUrl = 'url('+templateurl+'styles/bg/' + jQuery(this).attr('rel') + '.gif)';
    var a = jQuery(this);
      a.css({
          backgroundImage: backgroundUrl,
          backgroundRepeat: "repeat"
      })
  })
    
  jQuery('#style-switcher a.bg-box').click(function (e) {
      e.preventDefault();
      var backgroundUrl = 'url('+templateurl+'styles/bg/' + jQuery(this).attr('rel') + '.gif)';
      jQuery('body').css({
          backgroundImage: backgroundUrl,
          backgroundRepeat: "repeat"
      });
    jQuery.cookie("ts_cookie_bgimage",backgroundUrl)
  });
   
  var background = jQuery.cookie("ts_cookie_bgimage");
  

  if (background) {
      jQuery('body').css({
        backgroundImage: background,
        backgroundRepeat: "repeat"
      });
  }
         
});   
 
