function initWishBox(html) {
   var b = $('#wish-box')
   b.html(html)
  $('#wish-box').show()

  $('#wish-box a.cancel').click(function(){$('#wish-box').toggle()})
	$('#wish-box a.submit').click(function(){     
      $.ajax({
      			type: 'post',
      			url: 	'index.php?route=common/mailer/order',
      			dataType: 'html',
      			data: $('#wish-box input[type="text"],#wish-box input[type="hidden"], #wish-box :checked, #wish-box textarea'),
      			success: function (html) {  			       
      			     initWishBox(html)  					
      			},      	
      			timeout:10000,
      			complete: function () {
      			
    			}			
    		});    		
  })			
}


function initOrderBox(html)  {
   var box = $('#order-box')
		box.html(html)
    box.css({top:'50%',left:'50%',margin:'-'+(box.height() / 2)+'px 0 0 -'+(box.width() / 2)+'px'});			
		box.show(); 
    $('#basket').addClass('selected');
        
    $('#order-box a.continue').click(function() {
         $('#basket').removeClass('selected')
         $('#order-box').hide()
    })					
		
    $('#order-box a.order').click(function() {
        //init order step
        
       	$.ajax({
    			type: 'get',
    			url: 'index.php?route=checkout/address',
    			dataType: 'html',    			
    			success: function (html) {  			       
    			     initOrderBoxStep(html)  					
    			},      	
    			timeout:10000,
    			complete: function () {
    			
  			}			
  		});			
      });	    
}

function initOrderBoxStep(html)  {
   var box = $('#order-box')
   box.html(html)
   box.css({top:'50%',left:'50%',margin:'-'+(box.height() / 2)+'px 0 0 -'+(box.width() / 2)+'px'});
   
    $('#order-box a.back-cart').click(function() {        
         $.ajax({
          			type: 'get',
          			url: $(this).attr('href'),
          			dataType: 'html',          			
          			success: function (html) {          			     
          			     initOrderBox(html)          					
          			}                			          			          			
          			})
                
                return false			
          		});	
   
   $('#order-box a.back').click(function() {        
         $.ajax({
          			type: 'get',
          			url: $(this).attr('href'),
          			dataType: 'html',          			
          			success: function (html) {          			     
          			     initOrderBoxStep(html)          					
          			}                			          			          			
          			})
                
                return false			
          		});	
          		
  $('#order-box a.next').click(function () {
  
        
  		$.ajax({
  			type: 'post',
  			url: $(this).attr('href'),
  			dataType: 'html',
  			data: $('#order-box input[type="text"],#order-box input[type="hidden"], #order-box :checked'),
  			success: function (html) {  			       
  			     initOrderBoxStep(html)  					
  			},      	
  			timeout:10000,
  			complete: function () {
  			
  			}			
  		});
      		
  		return false
  })
  
}

jQuery(document).ready((function($) {  
  
  
  
	var wishEl = $('.wish')
	if(wishEl) {
								
		$('#content').append('<div id="wish-box" class="win"></div>');		
		
		wishEl.click(function() { $.ajax({
          			type: 'get',
          			url: 'index.php?route=common/mailer/order',
          			dataType: 'html',          			
          			success: function (html) {          			     
          			     initWishBox(html)          					
          			}                			          			          			
          			})
                
                return false			
          		});		
		wishEl.css('display','block')				
	}
	
	var i = window.location.href.lastIndexOf('#');
	if(i!=-1) {
    if(window.location.href.substr(i+1)=='sovicka-na-prani') {
        wishEl.click()
    }
  }		
	
	$('#add-to-cart').click(function () {
  		$.ajax({
  			type: 'post',
  			url: 'index.php?route=checkout/cart/ajax',
  			dataType: 'html',
  			data: $('#product :input'),
  			success: function (html) {  			       
  			       initOrderBox(html)
  					   $('#basket').load('index.php?route=module/cart/callback')
  			},      	
  			timeout:10000,
  			complete: function () {
  			
  			}			
  		});			
	});
	

	$('#content').append('<div id="order-box" class="win"><h3>Title</h3></div>');
	$('#basket').click(function() {
	         $.ajax({
          			type: 'get',
          			url: 'index.php?route=checkout/cart/ajax',
          			dataType: 'html',          			
          			success: function (html) {          			     
          			     initOrderBox(html)
          					//todo update module
          			}                			          			          			
          			})			
          		});	          	

	
	
}));  

