$(document).ready(function()
{
	var activeMenuImage;
	$('a[rel="external"]').click( function() {
        window.open( $(this).attr('href') );
        return false;
    });
	//alert('ready');
	$('.navigation').css('position', 'fixed'); 

	$('.navigation .menuitem').hover(function()
	{
		activeMenuImage=$(this).find('img').attr('src');
		if($(this).find('img').attr('class')!="active") $(this).find('img').attr('src',$(this).find('a').attr('rel'));
	},function()
	{
		if($(this).find('img').attr('class')!="active") $(this).find('img').attr('src',activeMenuImage);
	});
	
	$('.spinlogo').hover(function()
	{
		$(this).find('span').slideToggle('slow');
	},function()
	{
		$(this).find('span').slideToggle();
	});
	//social icons hover
	$('.social_facebook').hover(function()
	{
		$(this).attr('src','/images/social/face_on.gif');
	},function()
	{
		$(this).attr('src','/images/social/face.gif');
	});
	$('.social_twitter').hover(function()
	{
		$(this).attr('src','/images/social/twet_on.gif');
	},function()
	{
		$(this).attr('src','/images/social/twet.gif');
	});
	$('.social_youtube').hover(function()
	{
		$(this).attr('src','/images/social/tube_on.gif');
	},function()
	{
		$(this).attr('src','/images/social/tube.gif');
	});
	$('.social_flickr').hover(function()
	{
		$(this).attr('src','/images/social/flick_on.gif');
	},function()
	{
		$(this).attr('src','/images/social/flick.gif');
	});
	
	(function($) {
	$(function() { //on DOM ready
		$(".row-slider1").simplyScroll({
			autoMode: 'loop',
			speed: 1,
			loopOverload: 100,
			frameRate:100
		});
		
		$(".home-slider1").simplyScroll({
			autoMode: 'loop',
			speed: 1,
			loopOverload: 100,
			frameRate:100
		});
	});
})(jQuery);
/*
	//alternative background
	$('.span1,.span2,.span3').hoverIntent(function()
	{
		if($(this).find('img.altback').length!=0)
		{
			$(this).fadeOut("fast",function(){
			$(this).css('background','no-repeat url('+$(this).find('img.altback').attr('src')+')');
			$(this).fadeIn("fast");
			});
		}
	},function()
	{
		if($(this).find('img.altback').length!=0)
		{
			//$(this).fadeOut("fast",function(){
			$(this).css('background','no-repeat url('+$(this).find('img.origback').attr('src')+')');
			//$(this).fadeIn("fast");
			//});
		}
	});
*/
	//alternative background
	$('.span1,.span2,.span3,.span4,.span5,.span6,.span7,.span8').hover(function()
	{
		if($(this).find('img.altback').length>0)
		{
			$(this).css('background','no-repeat url('+$(this).find('img.altback').attr('src')+')');			
		}
	},function()
	{
		if($(this).find('img.altback').length>0)
		{
			$(this).css('background','no-repeat url('+$(this).find('img.origback').attr('src')+')');
		}
	});
	
	
	
	$('.span1,.span2,.span3,.span4,.span5,.span6,.span7,.span8').each(function()
	{
		if($(this).find('img.altback').length>0)
		{
			$(this).css('cursor','pointer');			
		}
	});
	
	$('.span1,.span2,.span3,.span4,.span5,.span6,.span7,.span8').each(function()
	{
		if($(this).find('a').attr("href")!="")
		{
			$(this).css('cursor','pointer');			
		}
	});
	
	$('.span1,.span2,.span3,.span4,.span5,.span6,.span7,.span8').click(function()
	{
		if($(this).find('a').attr("href")!="")
		{
			if($(this).find('a').attr("rel")=="external")
			{
				window.open($(this).find('a').attr("href"));
			}
			else
			{
				window.location=$(this).find('a').attr("href");
			}
		}
	});
	
	$('.product_item').click(function()
	{
		if($(this).find('a').attr("href")!="")
		{
			window.location=$(this).find('a').attr("href");			
		}
	});
	
	$('.product_item').hover(function()
	{
		$(this).find('.product_item_texts').show();
	},function()
	{
		$(this).find('.product_item_texts').hide();
	});
	
	
	
	$('.gender').hoverIntent(function()
	{
		//alert($(this).attr('gender'));
		if($(this).find(".collections").attr('rel')!="active")
		{
			$(this).find(".collections").slideToggle();
		}
	},function()
	{
		if($(this).find(".collections").attr('rel')!="active")
		{
			$(this).find(".collections").slideToggle();
		}
	});
	
	$('.gender').hover(function()
	{		
		mygender=$(this).attr('gender');
		if(mygender=="men")
		{
			$('li[rel=women]').fadeTo('fast',0.2);
		}
		else if(mygender=="women")
		{
			$('li[rel=men]').fadeTo('fast',0.2);
		}
	},function()
	{		
		mygender=$(this).attr('gender');
		if(mygender=="men")
		{
			$('li[rel=women]').fadeTo('fast',1);
		}
		else if(mygender=="women")
		{
			$('li[rel=men]').fadeTo('fast',1);
		}
	});
	
	
		
	
	///////COLOR PREVIEWS
	defaultActiveColor=0;
	if(self.document.location.hash.substring(1)!="")defaultActiveColor= self.document.location.hash.substring(1);
	//alert(defaultActiveColor);
	//$('.color-thumbs:first').show();
	//$('.product_color_sample_image:first').addClass('active');
	//$('.product_color_name_text span:first').show();
	//if(defaultActiveColor>0) defaultActiveColor = getRealDefaultActiveColor(defaultActiveColor);
	
	if(defaultActiveColor>0)
	{
	myRealColorIndex=$('#COLOR_COUNT'+defaultActiveColor).parent('div').find('.product_color_sample_image').index($('#COLOR_COUNT'+defaultActiveColor));
	defaultActiveColor=myRealColorIndex;
	}
	//alert(myRealColorIndex);
	$('.color-thumbs:eq('+defaultActiveColor+')').show();
	$('.product_color_sample_image:eq('+defaultActiveColor+')').addClass('active');
	$('.product_color_name_text>span').hide();
	$('.product_color_name_text>span:eq('+defaultActiveColor+')').css('display','block');
	$('.product_image img.productzoom').attr('src',$('.color-thumbs:eq('+defaultActiveColor+') a').attr('href'));
	$('.lightbox').attr('href',$('.color-thumbs:eq('+defaultActiveColor+') a').attr('rel'));
	$('.product-view-larger').attr('href',$('.color-thumbs:eq('+defaultActiveColor+') a').attr('rel'));
	
	$('.product_color_sample_image').hover(function()
	{
		myIndex = $(this).parent('div').find('.product_color_sample_image').index(this);
		$('.product_image img.productzoom').attr('src',$('.color-thumbs:eq('+myIndex+') a:first').attr('href'));
		$('.product_color_name_text>span').hide();
		$('.product_color_name_text>span:eq('+myIndex+')').show();
	},function()
	{
		myIndex2 = $('.product_color_sample_image.active').parent('div').find('.product_color_sample_image').index($('.product_color_sample_image.active'));
		$('.product_image img.productzoom').attr('src',$('.color-thumbs:eq('+myIndex2+') a:first').attr('href'));
		$('.product_color_name_text>span').hide();
		$('.product_color_name_text>span:eq('+myIndex2+')').show();
		//$('.lightbox').attr('href',$('.color-thumbs:eq('+myIndex2+') a:first').attr('rel'));
		//$('.product_color_sample_image.active').hide();
	});
	
	$('.product_color_sample_image').click(function()
	{
		myIndex = $(this).parent('div').find('.product_color_sample_image').index(this);
		$('.color-thumbs').hide();
		$('.color-thumbs:eq('+myIndex+')').show();
		$('.lightbox').attr('href',$('.color-thumbs:eq('+myIndex+') a:first').attr('rel'));
		$('.product-view-larger').attr('href',$('.color-thumbs:eq('+myIndex+') a:first').attr('rel'));
		
		$('.product_color_sample_image').removeClass('active');
		$(this).addClass('active');
		$('.product_color_name_text>span').hide();
		$('.product_color_name_text>span:eq('+myIndex+')').show();
		
		//display sizes for this color
		color_id=$(this).find("img").attr("rel");
		$('.color_sizes').hide();
		$('#sizes_'+color_id).show();
		
	});
	
	
	//activate sizes for first (active) color
	$('.product_color_sample_image.active').each(function()
	{
		color_id=$(this).find("img").attr("rel");
		$('.color_sizes').hide();
		$('#sizes_'+color_id).show();
	});
	
	
	
	$('.color-thumbs a').hover(function()
	{
		$('.product_image img.productzoom').attr('src',$(this).attr('href'));
	},function()
	{
		
	});
	
	$('.color-thumbs a').click(function()
	{
		$('.product_image img').attr('src',$(this).attr('href'));
		$('.lightbox').attr('href',$(this).attr('rel'));
		$('.product-view-larger').attr('href',$(this).attr('rel'));
		
		return false;
	});
	
	/*
	$("#wrap").anythingZoomer({
    	
    	   expansionSize: 30,
    	   speedMultiplier: 1.4
    	
    	});
	*/	
	
	/*$('.youtube_video').youTubeEmbed({
	width			: 'http://www.youtube.com/watch?v=ITUPeC85Ixg', 		// Height is calculated automatically
	video			: $(this).attr('rel'),
	progressBar	: false		// Hide the progress bar
	});*/

	$('.youtube_video1').each(function()
	{
		$(this).youTubeEmbed({
		video			: $(this).attr('rel'),
		width			: 102 		// Height is calculated automatically
		});
	});
	$('.youtube_video2').each(function()
	{
		$(this).youTubeEmbed({
		video			: $(this).attr('rel'),
		width			: 222 		// Height is calculated automatically
		});
	});
	$('.youtube_video3').each(function()
	{
		$(this).youTubeEmbed({
		video			: $(this).attr('rel'),
		width			: 341 		// Height is calculated automatically
		});
	});
	$('.youtube_video4').each(function()
	{
		$(this).youTubeEmbed({
		video			: $(this).attr('rel'),
		width			: 458 		// Height is calculated automatically
		});
	});
	$('.youtube_video5').each(function()
	{
		$(this).youTubeEmbed({
		video			: $(this).attr('rel'),
		width			: 579 		// Height is calculated automatically
		});
	});
	
	$('.youtube_video8').each(function()
	{
		$(this).youTubeEmbed({
		video			: $(this).attr('rel'),
		width			: 939 		// Height is calculated automatically
		});
	});
	
	
	
	$('a.lightbox').lightBox({fixedNavigation:true});
	$('a.product-view-larger').lightBox({fixedNavigation:true});

	pl_height=$('.productlist').height();
	xnum=Math.ceil(pl_height/119);
	pl_newheight=xnum*119;
	$('.productlist').height(pl_newheight);

	$('.products_menu').height(($('.main').height()-1));
	
	
	
	//ACTIVE GENDER AND COLLECTION
	$('.gender').each(function()
	{
		//alert($(this).find('.collections').attr('rel'));
		if($(this).find('.collections').attr('rel')=="active")
		{
			$(' .collections',this).css('display','block');
			//$('.collections').css('display','block');
		}
	});
	//$('.collections').css('display','block');
	
	
	//alert($(".color-thumbs").find('thumb').length());
	
	$('a.product_prev').hover(function()
	{
		$('img',this).attr('src','/images/icons/previous_on.gif');
	},function()
	{
		$('img',this).attr('src','/images/icons/previous_off.gif');
	});
	
	
	$('a.product_next').hover(function()
	{
		$('img',this).attr('src','/images/icons/next_on.gif');
	},function()
	{
		$('img',this).attr('src','/images/icons/next_off.gif');
	});
	
	$('a.product_back-to-overview').hover(function()
	{
		$('img',this).attr('src','/images/icons/back_overview_on.gif');
	},function()
	{
		$('img',this).attr('src','/images/icons/back_overview_off.gif');
	});
	
	$('a.product-view-larger').hover(function()
	{
		$('img',this).attr('src','/images/icons/view_larger.gif');
	},function()
	{
		$('img',this).attr('src','/images/icons/click_enlarge_off.gif');
	});
	
	
	
	//lightbox URL on page load
	//$('.lightbox').attr('href',$('.color-thumbs:eq(0) a:first').attr('rel'));
	//$('.product-view-larger').attr('href',$('.color-thumbs:eq(0) a:first').attr('rel'));
	
	
	//slider functionality
	$('.row-span1').each(function()
	{
		total_children_width=0;
		$('>li',this).each(function()
		{
			total_children_width+=$(this).find('.num_rows').attr('value')*1;
		});
		//alert(total_children_width);
		if(total_children_width>9) 
		{
			$(this).append('<li class="row_arrow_next"></li>');
			//alert(total_children_width);
		}
	});
	
	
	$('.row_arrow_prev').live('click', function() 
	{
		$(this).parent('ul').animate({marginLeft:"0px"},1000,function()
		{
			$(this).append('<li class="row_arrow_next"></li>');
		})
		$(this).remove();		
		});
		
	$('.row_arrow_next').live('click', function() 
	{		
		$(this).parent('ul').animate({marginLeft:"-833px"},1000,function()
		{
			$(this).append('<li class="row_arrow_prev"></li>');
		})
		$(this).remove();
		
		
	});
	
	aantalthumbs=$('.color-thumbs:first').find('.thumb').length;
	if(aantalthumbs>1)
	{
		$('.preview').show();
	}
	
	$('.productlist .set').each(function()
	{
		//alert();
		var my_max_height=0;
		$('>.product_item',this).each(function()
		{
			this_item_height=$(this).attr('mijnhoogte');
			if(this_item_height>my_max_height)
			{
				my_max_height=$(this).attr('mijnhoogte');
			}
		})
		
		$('>.product_item',this).each(function()
		{
			$(this).css('height',my_max_height);
			var text_hoogte=my_max_height-20;
			$(this).find('.product_item_texts').css('margin-top',text_hoogte);
		})
		//alert(my_max_height);
	});
	
	
});



