(function($){// namespace
	$(function(){// onload
		var origin = $("div.slider_box").width()
		var destination = '-'+origin
		$("div.slider_box ul")
			.tabs(
				{ fx: [
					{width: 'hide', duration: 500}, 
					{ duration: 500, marginLeft: "0px", opacity: 'show', width: origin }
				] }
			)
			// .tabs('rotate', 5000, true)
			.bind('select.ui-tabs',function(e, ui){
				$(ui.panel).css({'margin-left':origin, 'width': '0px'})
			});
		// $("div.slider_box div.slider_box ul").bind('select.ui-tabs',function(e,ui){
		// 	$("div.slider_box ul").tabs('rotate', null);
		// });
		
		$("div.compare[rel]:empty").each(function(){
			var compared_item_head = $("#"+$(this).attr('rel')).find("div.spotlight h3:first").text()
			$(this).append("<h3>Compare With: "+ compared_item_head +"</h3>") // compared item header
			$(this).append($("#"+$(this).attr('rel')).find("div.spotlight div.shop").clone())// compared item shop
			
			var compared_image = $("#"+$(this).attr('rel')).find("div.spotlight div.image").clone()
			$(this)
				.append(compared_image)
			$(this)
				.bind('mouseenter',function(){
					$(this).find('div.image').slideDown('slow');
				})
				.bind('mouseleave',function(){
					$(this).find('div.image').slideUp('slow');
				})
				.find('div.image').hide();
		});
		
		// Ads
		$('div.ads').prepend('<ul></ul>')
		$('div.ads div.slide').each(function(){
		  this.id = "slide"+Math.floor(10001*Math.random())
		  $(this).siblings('ul').append('<li><a href="#'+this.id+'">&bull;</a></li>')
		})
    count = parseInt($('div.ads div.slide').size(),10)
    random_slide_index = Math.floor(count*Math.random())
		$('div.ads').tabs({ fx: { opacity: 'toggle' }, selected: random_slide_index });
		$('div.ads').tabs('rotate', 7000)
		
	}); // end onload
})(jQuery); // end namespace
