

var rockwell = { src: '/js/rockwell.swf' };
var helvetica = { src: '/js/helvetica.swf' };

// Next, activate sIFR:
sIFR.activate(rockwell, helvetica);

sIFR.replace(rockwell, {
  selector: '#content h1',
wmode: 'transparent',
  css: '.sIFR-root { background-color: #151515; color: #f0e4ab; }'
});
sIFR.replace(rockwell, {
  selector: '#left h1',
wmode: 'transparent',
  css: '.sIFR-root { background-color: #151515; color: #f0e4ab; }'
});
sIFR.replace(rockwell, {
  selector: 'a.goToCheckout span',
wmode: 'transparent',
forceWrap: true,
  css: '.sIFR-root { width: 170px; background-color: #151515; color: #f0e4ab; }'
});


sIFR.replace(rockwell, {
  selector: 'h1.kosedressvelger',
wmode: 'transparent',
  css: '.sIFR-root { background-color: #151515; text-align: center; margin-left: 60px; position: relative; top: 40px; color: #f0e4ab; }'
});






$(document).ready(function(){
	
	
	
  var currentPosition = 0;
  var slideWidth = 560;
  var slides = $('.slide');
  var numberOfSlides = slides.length;

	

  // Remove scrollbar in JS
  $('#dresserContainer').css('overflow', 'hidden');

  // Wrap all .slides with #slideInner div
  slides
  .wrapAll('<div id="slideInner"></div>')
  // Float left to display horizontally, readjust .slides width
  .css({
    'float' : 'left',
    'width' : slideWidth
  });

  // Set #slideInner width equal to total width of all slides
  $('#slideInner').css('width', slideWidth * numberOfSlides);

  // Insert left and right arrow controls in the DOM
  $('#dresser')
    .prepend('<span class="control" id="leftControl">Move left</span>')
    .append('<span class="control" id="rightControl">Move right</span>');

  // Hide left arrow control on first load
  manageControls(currentPosition);
	var currentSize = $('select#size').val();

	$("a.sendButton").attr({id : "prodID_"+(currentPosition+1)+"_size_"+(currentSize)});
	$("a.sendButton").attr({href : "inc/functions.php?action=addToBasket&productID="+(currentPosition+1)+"&size="+(currentSize)});
	
	
	
  // Create event listeners for .controls clicks
  $('.control')
    .bind('click', function(){
    // Determine new position
      currentPosition = ($(this).attr('id')=='rightControl')
    ? currentPosition+1 : currentPosition-1;

      // Hide / show controls
      manageControls(currentPosition);
      // Move slideInner using margin-left
      $('#slideInner').animate({
        'marginLeft' : slideWidth*(-currentPosition)
      });

	// Getting sizes
	$("#dresserBottom").empty();
	$("#dresserBottom").html('<img src="img/loader.gif">');
		var productID = (currentPosition+1);
		$.ajax({  
		type: "POST",  
		url: "inc/functions.php",  
		data: { productID: productID, action: "getSizes"},  
		success: function(theResponse) {
				
				$("div#dresserBottom").empty();
				$("div#dresserBottom").html(theResponse);
				
				var currentSize = $('select#size').val();
				$("a.sendButton").attr({id : "prodID_"+(currentPosition+1)+"_size_"+(currentSize)});
				$("a.sendButton").attr({href : "inc/functions.php?action=addToBasket&productID="+(currentPosition+1)+"&size="+(currentSize)});
				$("input.dress").attr({value : currentPosition+1});
				
				$('select#size').change(function () {
						var currentSize = $('select#size').val();
						$("a.sendButton").attr({id : "prodID_"+(currentPosition+1)+"_size_"+(currentSize)});
						$("a.sendButton").attr({href : "inc/functions.php?action=addToBasket&productID="+(currentPosition+1)+"&size="+(currentSize)});
				} 
				);
				
							
				$(".addToCart a.sendButton").click(function() {
					var productIDValSplitter 	= (this.id).split("_");
					var productIDVal 			= productIDValSplitter[1];

					var sizeValSplitter		 	= (this.id).split("_");
					var sizeVal 				= sizeValSplitter[3];
					$("#notificationsLoader").html('<img src="img/loader.gif">');
					
					$.ajax({  
					type: "POST",  
					url: "inc/functions.php",  
					data: { productID: productIDVal, size: sizeVal, action: "addToBasket"},  
					success: function(theResponse) {
						sizeVal = sizeVal.toUpperCase();
						if($("p#emptycart").length > 0) {
							$("p#emptycart").remove();
							$("a.goToCheckout").css("display", "block");
							
						} 
						if( $("#productID_" + productIDVal + "_productSize_" + sizeVal).length > 0){
							$("#productID_" + productIDVal + "_productSize_" + sizeVal).animate({ opacity: 0 }, 500, function() {
								$("#productID_" + productIDVal + "_productSize_" + sizeVal).before(theResponse).remove();
							});				

							$("#productID_" + productIDVal + "_productSize_" + sizeVal).animate({ opacity: 0 }, 500);
							$("#productID_" + productIDVal + "_productSize_" + sizeVal).animate({ opacity: 1 }, 500);
							$("#notificationsLoader").empty();			
						} else {
							$("#cartItems li:first").before(theResponse);
							$("#cartItems li:first").hide();
							$("#cartItems li:first").show("slow");  
							$("#notificationsLoader").empty();			
						}

					}  
					});  

				});

		}  
		});

	
	var currentSize = $('select#size').val();
	$("a.sendButton").attr({id : "prodID_"+(currentPosition+1)+"_size_"+(currentSize)});
	$("a.sendButton").attr({href : "inc/functions.php?action=addToBasket&productID="+(currentPosition+1)+"&size="+(currentSize)});
    });

  // manageControls: Hides and shows controls depending on currentPosition
  function manageControls(position){
    // Hide left arrow if position is first slide
    if(position==0){ $('#leftControl').hide(); $('#placeholder').show(); }
    else{ $('#leftControl').show()
 			$('#placeholder').hide(); }
    // Hide right arrow if position is last slide
    if(position==numberOfSlides-1){ $('#rightControl').hide() }
    else{ $('#rightControl').show() }
    }
  });


	
$(document).ready(function(){ 

	$("#cartItems li:first").hide();

	



	$("#cartItems li img").live("click", function(event) { 

		var productIDValSplitter 	= (this.id).split("_");
		var productIDVal 			= productIDValSplitter[1];	
		
		var sizeValSplitter		 	= (this.id).split("_");
		var sizeVal 				= sizeValSplitter[3];

		$("#notificationsLoader").html('<img src="img/loader.gif">');

		$.ajax({  
		type: "POST",  
		url: "inc/functions.php",  
		data: { productID: productIDVal, size: sizeVal, action: "deleteFromBasket"},  
		success: function(theResponse) {
			if($("p#emptycart").length == 0) {
				$("#cartItems ul").append("<p id='emptycart'>Din handlevogn er tom</p>");
				$("a.goToCheckout").css("display", "none");
			}
			$("#productID_" + productIDVal + "_productSize_" + sizeVal).hide("slow",  function() {$(this).remove();});
			$("#notificationsLoader").empty();

		}  
		});  

	});
	
	

});



