  jQuery(document).ready(function($) {
    
	/*************** COLOR PICKER ******************/
	$('#colorpicker').ColorPicker({
			onShow: function (colpkr) {
				$(colpkr).fadeIn("fast");
				return false;
			},
			onHide: function (colpkr) {
				$(colpkr).fadeOut("fast");
				return false;
			},
			onChange: function (hsb, hex, rgb) {
				
				var bgcolor = hex;
				$('body').css({
					"background-color": '#' + bgcolor
				});     
				$.cookie("ts_cookie_bgcolor", bgcolor);   
			},
      color: '#2d84b6'
    });
	
	$('#colorpicker2').ColorPicker({
			onShow: function (colpkr) {
				$(colpkr).fadeIn("fast");
				return false;
			},
			onHide: function (colpkr) {
				$(colpkr).fadeOut("fast");
				return false;
			},
			onChange: function (hsb, hex, rgb) {
				
				var headercolor = hex;
				$('h1, h2, h3, h4, h5, h6, .posttitle a').css({
					"color": '#' + headercolor
				});     
				Cufon.refresh();
				$.cookie("ts_cookie_headercolor", headercolor);   
				
			},
      color: '#2d84b6'
    });
	/*************** END COLOR PICKER ******************/
    
	/*************** COLOR BOX BACKGROUND **************/
    $('#style-switcher a.color-box').each(function (i) {
        var a = $(this);
        a.css({
            backgroundColor: '#' + a.attr('rel')
        });
    });
    /*************** END COLOR BOX BACKGROUND **********/
	
	/*************** BACKGROUND PATTERN BOX **************/
	$('#style-switcher a.bg-box').each(function (i) {
		var backgroundUrl = 'url(styles/bg/' + $(this).attr('rel') + '.png)';
		var a = $(this);
		a.css({
			backgroundImage: backgroundUrl,
	  		backgroundRepeat: "repeat"
		})
	});
	/*************** END BACKGROUND PATTERN BOX **************/
	
	
    
   var switcher_skins = $('#style-switcher a.color-box');
   var switcher_link = $('#skins-switcher');
   var download_btn = $('#download-button img');
   
   switcher_skins.each(function(i) {
    var color = $(this).attr('rel');
    
	if(color == "765d99") {
      switcher_link.attr('href',"styles/purple/purple.css");
      var atrrHref = switcher_link.attr('href');
	  
	  download_btn.attr('src',"styles/purple/button-download.png");
    }
	if(color == "f06613") {
      switcher_link.attr('href',"styles/orange/orange.css");
      var atrrHref = switcher_link.attr('href');
	  
	  download_btn.attr('src',"styles/orange/button-download.png");
    }
	if(color == "12c0c2") {
      switcher_link.attr('href',"styles/cyan/cyan.css");
      var atrrHref = switcher_link.attr('href');
	  
	  download_btn.attr('src',"styles/cyan/button-download.png");
    }
    if(color == "000000") {
      switcher_link.attr('href',"styles/black/black.css");
      var atrrHref = switcher_link.attr('href');
	  
	  download_btn.attr('src',"styles/black/button-download.png");
    }
	if(color == "2d84b6") {
      switcher_link.attr('href',"styles/blue/blue.css");
      var atrrHref = switcher_link.attr('href');
	  
	  download_btn.attr('src',"styles/blue/button-download.png");
    }
    if(color == "2f7609") {
      switcher_link.attr('href',"styles/green/green.css");
      var atrrHref = switcher_link.attr('href');
	  
	  download_btn.attr('src',"styles/green/button-download.png");
    }
    if(color == "e0b200") {
      switcher_link.attr('href',"styles/yellow/yellow.css");
      var atrrHref = switcher_link.attr('href');
	  
	  download_btn.attr('src',"styles/yellow/button-download.png");
    }
    if(color == "990000") {
      switcher_link.attr('href',"styles/red/red.css");
      var atrrHref = switcher_link.attr('href');
	  
	  download_btn.attr('src',"styles/red/button-download.png");
    }
	if (color == "454545") {
      switcher_link.attr('href',"styles/grey/grey.css");
      var atrrHref = switcher_link.attr('href');
	  
	  download_btn.attr('src',"styles/grey/button-download.png");
    }
   });
   
   
   /********** switcher_skins.click ***************/
   switcher_skins.click(function(e) {
    var color = $(this).attr('rel');
    var skins;
    
    if (color == "454545") {
      switcher_link.attr('href',"styles/grey/grey.css");
	  download_btn.attr('src',"styles/grey/button-download.png");
      var atrrHref = switcher_link.attr('href');
	  $("#logo img").attr('src','styles/grey/logo.png');
    }
    if(color == "990000") {
      switcher_link.attr('href',"styles/red/red.css");
	  download_btn.attr('src',"styles/red/button-download.png");
	  
      var atrrHref = switcher_link.attr('href');
	  $("#logo img").attr('src','styles/red/logo.png');
    }
    if(color == "e0b200") {
      switcher_link.attr('href',"styles/yellow/yellow.css");
	  download_btn.attr('src',"styles/yellow/button-download.png");
	  
      var atrrHref = switcher_link.attr('href');
	  $("#logo img").attr('src','styles/yellow/logo.png');
    }
    if(color == "2f7609") {
      switcher_link.attr('href',"styles/green/green.css");
	  download_btn.attr('src',"styles/green/button-download.png");
	  
      var atrrHref = switcher_link.attr('href');
	  $("#logo img").attr('src','styles/green/logo.png');
    }
    if(color == "2d84b6") {
      switcher_link.attr('href',"styles/blue/blue.css");
	  download_btn.attr('src',"styles/blue/button-download.png");
	  
      var atrrHref = switcher_link.attr('href');
	  $("#logo img").attr('src','styles/blue/logo.png');
    }
	if(color == "000000") {
      switcher_link.attr('href',"styles/black/black.css");
	  download_btn.attr('src',"styles/black/button-download.png");
	  
      var atrrHref = switcher_link.attr('href');
	  $("#logo img").attr('src','styles/black/logo.png');
    }
	if(color == "12c0c2") {
      switcher_link.attr('href',"styles/cyan/cyan.css");
	  download_btn.attr('src',"styles/cyan/button-download.png");
	  
      var atrrHref = switcher_link.attr('href');
	  $("#logo img").attr('src','styles/cyan/logo.png');
    }
	if(color == "f06613") {
      switcher_link.attr('href',"styles/orange/orange.css");
	  download_btn.attr('src',"styles/orange/button-download.png");
	  
      var atrrHref = switcher_link.attr('href');
	  $("#logo img").attr('src','styles/orange/logo.png');
    }
	if(color == "765d99") {
      switcher_link.attr('href',"styles/purple/purple.css");
	  download_btn.attr('src',"styles/purple/button-download.png");
	  
      var atrrHref = switcher_link.attr('href');
	  $("#logo img").attr('src','styles/purple/logo.png');
    }
	
	Cufon.refresh();
	
    $.cookie("ts_cookie_pattern", null);

    $.cookie("ts_cookie_color", color);  
    $.cookie("ts_cookie_skins", atrrHref);
	
    return false;
  });
  /********** end switcher_skins.click ***************/
  
  /********** patternbox.click ***************/
  $('#style-switcher a.pattern-box').click(function (e) {
      e.preventDefault();
      var patternUrl = 'url(styles/bg/' + $(this).attr('rel') + '.png)';
      $('body').css({
          backgroundImage: patternUrl,
          backgroundRepeat: "repeat"
      });
      $.cookie("ts_cookie_bgimage",null);
      $.cookie("ts_cookie_pattern", patternUrl)
  });
  /********** end patternbox.click ***************/
  
  /********** bg-box.click ***************/
  $('#style-switcher a.bg-box').click(function (e) {
      e.preventDefault();
      var backgroundUrl = 'url(styles/bg/' + $(this).attr('rel') + '.png)';
      $('body').css({
          backgroundImage: backgroundUrl,
          backgroundRepeat: "repeat"
      });
    $.cookie("ts_cookie_bgimage",backgroundUrl);
  });
  /********** end bg-box.click ***********/
   
  var color 			= $.cookie("ts_cookie_color");
  var bgcolor 			= $.cookie("ts_cookie_bgcolor");
  var ecobiz_skins 		= $.cookie("ts_cookie_skins");
  var defaultPattern	= $.cookie("ts_cookie_defaultBg");
  var pattern 			= $.cookie("ts_cookie_pattern");
  var background 		= $.cookie("ts_cookie_bgimage");
  var headingcolor		= $.cookie("ts_cookie_headercolor");
  
  if(color){
	if (color == "454545") {
		$("#logo img").attr('src','styles/grey/logo.png');
		download_btn.attr('src',"styles/grey/button-download.png");
	}else if (color == "990000") {
		$("#logo img").attr('src','styles/red/logo.png');
		download_btn.attr('src',"styles/red/button-download.png");
	}else if (color == "e0b200") {
		$("#logo img").attr('src','styles/yellow/logo.png');
		download_btn.attr('src',"styles/yellow/button-download.png");
	}else if (color == "2f7609") {
		$("#logo img").attr('src','styles/green/logo.png');
		download_btn.attr('src',"styles/green/button-download.png");
	}else if (color == "2d84b6") {
		$("#logo img").attr('src','styles/blue/logo.png');
		download_btn.attr('src',"styles/blue/button-download.png");
	}else if (color == "000000") {
		$("#logo img").attr('src','styles/black/logo.png');
		download_btn.attr('src',"styles/black/button-download.png");
	}else if (color == "12c0c2") {
		$("#logo img").attr('src','styles/cyan/logo.png');
		download_btn.attr('src',"styles/cyan/button-download.png");
	}else if (color == "f06613") {
		$("#logo img").attr('src','styles/orange/logo.png');
		download_btn.attr('src',"styles/orange/button-download.png");
	}else if (color == "765d99") {
		$("#logo img").attr('src','styles/purple/logo.png');
		download_btn.attr('src',"styles/purple/button-download.png");
	}
  }
  
  if (ecobiz_skins) {
    $("#skins-switcher").attr("href",ecobiz_skins);
  }
  
  if(bgcolor){
	$("body").css({
		"background-color" : "#"+bgcolor
	});  
  }

  if (background) {
      $('body').css({
        backgroundImage: background,
        backgroundRepeat: "repeat"
      });
  }
  
  if(headingcolor){
  	$('h1, h2, h3, h4, h5, h6, .posttitle a').css({
		"color": '#'+headingcolor
	});
  }
         
});   
 
