/* THEME CHANGER */

/*$(document).ready(function() {
     
  $('a#toggleColorPicker').bind('click', function() {
    if ($('a#toggleColorPicker').hasClass('show'))
      toggleColorPicker('show');
    else
      toggleColorPicker('hide');
      
    return false;
  });
  
  $('a#themeBasic').bind('click', function() {
    	switchStyle('basic', false);
  		return false;
  	});
  	
  $('a#themeGreen').bind('click', function() {
    	switchStyle('themeGreen', false);
  		return false;
  	});
  	
	$('a#themePurple').bind('click', function() {
  	switchStyle('themePurple', false);
		return false;
	});
	
});*/

$(document).ready(function() {
  
	$('a#toggleColorPicker').bind('click', function() {
		if ($('a#toggleColorPicker').hasClass('show'))
			toggleColorPicker('show');
		else
			toggleColorPicker('hide');
	      
	    return false;
	 });	
	
	// assign click events to all theme buttons
  
  $('a.themeSelect').bind('click', function() {
	  
	  switchStyle($(this).attr('href'), false);  
	  
	  return false;
  });
  
});

function toggleColorPicker(action)
{
  if (action == 'show')
  {
    $('a#toggleColorPicker').removeClass('show');
    $('a#toggleColorPicker').addClass('hide');
    $('div#colorPicker').stop().animate({height: "113px"}, 500);
  }
  else
  {
    $('a#toggleColorPicker').removeClass('hide');
    $('a#toggleColorPicker').addClass('show');
    $('div#colorPicker').stop().animate({height: "0px"}, 300);
  }
}

function switchStyle(name, disabled)
{
	$('link[rel*=style][title]').each(function(i) {
     
      this.disabled = true;
      if (this.getAttribute('title') == name) {
        this.disabled = disabled;
      }
   });
   
    // read the old cookie to get the current theme
    var oldTheme = getCookie('StopSiteStyle');
	
    if (oldTheme == null || oldTheme == '')
    	oldTheme = 'default';
    
    // set a new cookie
    setCookie('StopSiteStyle', name, 1000);
   
    // replace the footer images
    $.each($('#footerLinks img[src*=/themes/'+oldTheme+'], #content input[src*=/themes/'+oldTheme+']'), function(index, value){
	    value.src = value.src.replace('/themes/' + oldTheme, '/themes/' + name);
   });
}

