$("document").ready(function () {
	$("#browser").treeview({unique: true, persist: true});

	// Navigation
	$("#nav li a").mouseover(function() {
			$(this).stop().animate( 
				{backgroundColor:"#ccc"},
				{duration:200}
			);
		});
	$("#nav li a").mouseout(function () {
			var color = $(this).parent().css('backgroundColor');
			$(this).stop().animate( 
				{backgroundColor: color}, 
				{duration:200}
			);
	 	});
	 	
	// Slideshow
	// $('#slideshow').cycle();	 

	// Gallery
	$('#gallery #images').after('<ul id="gallery-nav" class="span-14 nav">').cycle({ 
    fx:     'fade', 
    speed:  'fast', 
    timeout: 0, 
    pager:  '#gallery-nav', 
     
    // callback fn that creates a thumbnail to use as pager anchor 
    pagerAnchorBuilder: function(idx, slide) { 
    		if (idx == 0)
    			$('#gallery-nav').show();
    			
        return '<li><a href="' + slide.src + '"><img src="' + slide.src + '" width="70" /></a></li>'; 
    } 
	});
		
	// Smoothscroll
	$(document).ready(function(){
		$.smoothAnchors(2000, "swing", false);
	});

	// lightBox
	$(".entry a[href*='/s1600-h']").each(function() {
		var h = $(this).attr('href');
		h = h.replace('/s1600-h', '/s1600');
		$(this).attr('href', h);
	});

	$(".entry a[href^='http://vimeo.com']").each(function() {
		var h = $(this).attr('href');
		var id = h.split('/');
		id = id[3];
		$(this).attr('href', 'http://vimeo.com/moogaloop.swf?clip_id='+id+'&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=00ADEF&amp;fullscreen=1');
	});

	$(".entry a[href$=.jpg], .entry a[href$=.JPG], .entry a[href$=.png], .entry a[href$=.PNG], .entry a[href$=.gif], .entry a[href$=.GIF], .entry a[href$=.jpeg], .entry a[href$=.JPEG]").colorbox({width:"80%", height:"80%"});
	
	$(".entry a[href^=http://vimeo.com]").colorbox({width:"80%", height:"80%", iframe:true});

	// Shop
	$('.simpleCart_emailcheckout').click(simpleCart.emailCheckout);
	
	equalHeight($('.simpleCart_shelfItem'));
	
	// Orders
	$('#order .itemQuantity input').focus(function () { $(this).blur(); });
	
	if ($('#checkout-form').length > 0) {
		// Total Values
		$('#checkout-form form input[name="email-orders[order-shipping-cost]"]').val(simpleCart.currencyStringToValue($('.simpleCart_shippingCost').text()));
		$('#checkout-form form input[name="email-orders[order-total]"]').val(simpleCart.currencyStringToValue($('.simpleCart_finalTotal').text()));
	
		// Cart Items
		$('#order .itemContainer .itemName').each(function (i) {
			var val = $(this).text();
			$('#checkout-form form').append('<input name="order-items['+(i+1)+'][order-num]" type="hidden" value="email-orders[system:id]" /><input name="order-items['+(i+1)+'][item-name]" type="hidden" value="'+val+'" />');	
		});
		
		$('#order .itemContainer .itemQuantity').each(function (i) {
			var val = $(this).find('input').attr('value');
			$('#checkout-form form').append('<input name="order-items['+(i+1)+'][item-quantity]" type="hidden" value="'+val+'" />');	
		})
		
		$('#order .itemContainer .itemTotal').each(function (i) {
			var val = simpleCart.currencyStringToValue($(this).text());
			$('#checkout-form form').append('<input name="order-items['+(i+1)+'][item-price]" type="hidden" value="'+val+'" />');	
		});
		
		$('#order .itemContainer .itemthumb').each(function (i) {
			var val = $(this).find('img').attr('src');
			$('#checkout-form form').append('<input name="order-items['+(i+1)+'][item-image]" type="hidden" value="'+val+'" />');	
		});
	}	
});

function equalHeight(group) {
  tallest = 0;
  group.each(function() {
    thisHeight = $(this).height();
    if(thisHeight > tallest) {
      tallest = thisHeight;
    }
  });
  group.height(tallest);
}

swfobject.embedSWF("http://www.lesettes.com/workspace/swf/header.swf", "slideshow", "100%", "100%", "9.0.0");

//swfobject.registerObject("flash-header", "9.0.0", "expressInstall.swf");