jQuery.noConflict();

// Document Ready Event
jQuery(document).ready(function(){
	
	// Featured Slide Thing
	
	var items = jQuery('.featured li');
	var item_width = 483;
	var max_margin = items.length * item_width - item_width;
	var animstatus = false;
	var user_click = false;
	var animation_speed = 1000;
	var auto_speed = 5000;
	
	
	jQuery('.featured .fthumbs div').each(function(i,link) {
		var index = i+1;
		jQuery(link).click(function(e) {
			e.preventDefault();
			user_click = true;
			
			moveFeature(index);
		});
	});
	
	function moveFeature(location) {
		if(animstatus == false) {
			animstatus = true;
			var feature = jQuery('.featured ul');
			var pos = parseInt(jQuery(feature).css('left'));
			
			if(location) {
				if(location=='next') {
					if(pos == -max_margin){
						left = 0;
					}
					else {
						left = pos-item_width;
					}
				}
				else if(location=='back') {
					if(pos == 0){
						left = -max_margin;
					}
					else {
						left = pos+item_width;
					}
				}							
				else {
					left = -(item_width*location)+item_width;
				}
				
				var item = Math.abs(left/item_width);
				jQuery('.featured .fthumbs div').removeClass('active');
				jQuery('.featured .fthumbs div:eq('+item+')').addClass('active');
				
				feature.animate({left: left},animation_speed,"swing",function() {
					animstatus = false;
				});
			}
		}
	}
	
	function feature_automove() {
		if(user_click == true) {
			user_click = false;
		}
		else {
			moveFeature('next');
		}
	}
	var feature_auto = setInterval(feature_automove, auto_speed);
	
	// cookie functions http://www.quirksmode.org/js/cookies.html
	function createCookie(name,value,days) {
		if (days)
		{
			var date = new Date();
			date.setTime(date.getTime()+(days*24*60*60*1000));
			var expires = "; expires="+date.toGMTString();
		}
		else var expires = "";
		document.cookie = name+"="+value+expires+"; path=/";
	}
	function readCookie(name) {
		var nameEQ = name + "=";
		var ca = document.cookie.split(';');
		for(var i=0;i < ca.length;i++)
		{
			var c = ca[i];
			while (c.charAt(0)==' ') c = c.substring(1,c.length);
			if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
		}
		return null;
	}
	function eraseCookie(name)
	{
		createCookie(name,"",-1);
	}
	// /cookie functions
	
	/**
	* Styleswitch stylesheet switcher built on jQuery
	* Under an Attribution, Share Alike License
	* By Kelvin Luck ( http://www.kelvinluck.com/ )
	**/

	jQuery(document).ready(function() {
		jQuery('.styleswitch').click(function()
		{
			switchStylestyle(this.getAttribute("rel"));
			return false;
		});
		var c = readCookie('style');
		if (c) switchStylestyle(c);
	});

	function switchStylestyle(styleName)
	{
		jQuery('link[@rel*=style][title]').each(function(i)
		{
			this.disabled = true;
			if (this.getAttribute('title') == styleName) this.disabled = false;
		});
		createCookie('style', styleName, 365);
	}
	
	jQuery(".atabs .tabs a").each(function(i) {
		jQuery(this).click(function(e){
			e.preventDefault();
							
			jQuery(".atabs .tabs a").removeClass('active');
			jQuery(this).addClass('active');
			
			jQuery('#atabs_content').empty().html(jQuery(this.getAttribute("rel")).html());
		});
	});
});


