$(document).ready(function(){
	$('#baseRSS').click(function(){
		$('#rssTip').toggle();
		if($('#rssTip').css('display') == 'block'){
			$('#baseRSS').css('background-position', '-130px -70px');
		}
		else{
			$('#baseRSS').css('background-position', '-130px -40px')
		}
	});
	
	$('.scrollTop').click(function(){
		$('html, body').animate({
        	scrollTop: '0px'
		}, 1000);
		return false;
	});
	
	$('a.share').click(function(){
		var entryid = $(this).attr('rel');
		$(this).parent().append(
		'<div class="shareBox">'+
		'<ul class="clearfix">'+
		'	<li><a href="http://twitter.com/home?status=http://www.nomadshop.net/index.php/main/entry/'+entryid+'">Twitter</a></li>'+
		'	<li><a href="http://www.facebook.com/share.php?u=http://www.nomadshop.net/index.php/main/entry/'+entryid+'" target="_blank">Facebook</a></li>'+
		'	<li><a href="http://www.google.com/buzz/post?url=http://www.nomadshop.net/index.php/main/entry/'+entryid+'" target="_blank">Google Buzz</a></li>'+
		'	<li><a class="closeShare" href="#">&times;</a></li>'+	
		'</ul>'+
		'</div>'
		);
		$(this).hide();
		$(this).parent().find('a.closeShare').click(function(){
			var parentElement = $(this).parent().parent().parent().parent();
			$(parentElement).find('a.share').show();
			$(parentElement).find('div.shareBox').remove();
			return false;
		});
		return false;
	});
	
	$('.jqTransformSelectWrapper ul li a').click(function(){
		var index = parseInt($('div.jqTransformSelectWrapper ul li a.selected').attr('index'));
		var vval = $('#variantselect option:eq('+index+')').attr('value');
		$('#variantid').val(vval);
	});
	
	if($('#homeShop').length){			// home page
		$(window).load(function(){
			$('#homeShop img.spinner').hide();
			$('#homeShop img.w_alpha').hide();
			$('#homeFeature img.spinner').hide();
			$('#homeFeature img.w_alpha').hide();
		});
	}
	else if($('#editorialGallery').length){
		$(window).load(function(){
			$('#editorialGallery img.spinner').hide();
			$('#editorialGallery img.w_alpha').hide();
		});
	}
});


(function($){
 $.fn.fadeShow = function(options) {
    
  var defaults = {
  	duration: 500,
	prev: $('a.prev'),
	next: $('a.next'),
	auto: false,
	autoDuration: 4000
  };
  
  var options = $.extend(defaults, options);
    
  return this.each(function() {
   	obj = $(this);
	var slideTimer = 0;
	
   	$(obj).find('li:gt(0)').hide();
	$(obj).find('li:first').addClass('active');
	
	if (options.auto) {
		slideTimer = setInterval(function(){
			jumpToNext(obj);
		}, options.autoDuration);
	}
	
	$(options.prev).click(function(){
		jumpToPrev(obj);
		clearInterval(slideTimer);
		return false;
	});
	
	$(options.next).click(function(){
		jumpToNext(obj);
		clearInterval(slideTimer);
		return false;
	});
   
  });
  
  function jumpToPrev(obj){
  	var cIndex = $(obj).find('li').index($(obj).find('li.active'));
	if(cIndex == 0){
		jumpTo(obj, $(obj).find('li').length - 1);
	}
	else{
		jumpTo(obj, cIndex - 1);
	}
  }
  
  function jumpToNext(obj){
  	var cIndex = $(obj).find('li').index($(obj).find('li.active'));
	if(cIndex == $(obj).find('li').length - 1){
		jumpTo(obj, 0);
	}
	else{
		jumpTo(obj, cIndex + 1);
	}
  }
  
  function jumpTo(obj, index){
  		$(obj).find('li.active').fadeOut(options.duration).removeClass('active');
		$(obj).find('li:eq('+index+')').addClass('active').fadeIn(options.duration);
  }
  
 };
})(jQuery);


