jQuery(document).ready(function($){
	$('<link rel="stylesheet" href="themeswitcher.css" type="text/css" media="screen" />').appendTo('head');
	
	var open = false;
	$('#themeswitcher_toggle').click(function() {
		if(open == false) {
			$('#themeswitcher').animate({
				'left': '-55px'
			}, 50);
			$('#themeswitcher').animate({
				'left': '-3px'
			});
			open = true;
		} else {
			$('#themeswitcher').animate({
				'left': '0'
			}, 50);
			$('#themeswitcher').animate({
				'left': '-47px'
			});
			open = false;
		}
	});
	
	$('.themeswitcher_style').hover(function(){
		$(this).animate({
			'opacity': '0.7'
		}, 150);
		$(this).find('.themeswitcher_style_desc').css({
			'display': 'block'
		});
		$(this).find('.themeswitcher_style_desc').animate({
			'opacity': '1'
		}, 150);
	}, function(){
		$(this).animate({
			'opacity': '1'
		}, 150);
		$(this).find('.themeswitcher_style_desc').animate({
			'opacity': '0'
		}, 150);
		var thisthis = this;
		setTimeout(function(){
			$(thisthis).find('.themeswitcher_style_desc').css({
				'display': 'none'
			});
		}, 150);
	});
	
	$('.themeswitcher_style').click(function(){
		var id = $(this).attr('id');
		var parts = id.split('_');
		var style = parts[2];
		
		
		var stylesheet = $('link').attr('href');
		var absolute = stylesheet.lastIndexOf("/")
		
		// if path is absolute
		if(absolute == -1) {
			// if it's the standard stylesheet
			if(style == 'classic') {
				$('link').first().attr('href', 'style.css');
			} 
			// or not the standard stylesheet
			else {
				$('link').first().attr('href', 'style_' + style + '.css');
			}
		}
		// or relative path
		else {
			// TODO
		}
	});
});
