  $(document).ready(function(){	
	$("#slider").easySlider();
	$('#options').tabs();	  
    $(".quick_info").fancybox();		
	  
	$("#amazon_proceed").attr('target', 'blank');
   	$("#amazon_proceed").click(function(){$("#transaction_id").show('slow')});
	
	$(".edit_order_id").click(function(){
	    $('#' + this.id.replace('edit_', '')).html($('#' + this.id.replace('order_id', 'holder')).html());
	    return false;
	});
	  
    $("#slider .wrapper fieldset a").click(function(){
        btn_id = $(this).attr('class').replace('btn ', '');
      	btn_id = btn_id.replace(' tooltip', '');
      	btn_id = btn_id.replace(' last', '');
	        calculate(btn_id);
      	return false;
    });
    
    $("#loading").ajaxStart(function(){
       $(this).show();
    });
    $("#loading").ajaxStop(function(){
       $(this).hide();
    });

    $('#member-acc .pagination').html('<a class="more" href="#">more</a>');
    $('#member-acc .pagination a').click(function(){
        var total_pages = $('#total_pages').html();       
        page = typeof(page) != 'undefined' ? page : 2;
        if(page == total_pages) $('.pagination').hide(); 
        var snippet = $.ajax({
          url: window.location + '?page=' + page,
          async: false
         }).responseText;         
        $('#history-list').append(snippet);
        page = page + 1;                      
        return false;
    });
    
    $('a.cart_link').live('click', function(){        
       
        $.ajax({ url: $(this).attr('href'), context: document.body, success: function(){                        
            $('#cartinfo').load(window.location.href.replace('search/products', 'cart/mini_cart')); 
            $('#search_cart').load(window.location.href.replace('search/products', 'cart/search_cart')); 
            $('#cartinfo').fadeOut();           
            $('#cartinfo').fadeIn();
            $('#search_cart').fadeOut();           
            $('#search_cart').fadeIn();
        }});
        
        if($(this).parent().attr('class') == 'add'){
            $(this).parent().attr('class', 'remove');
            $(this).attr('href', $(this).attr('href').replace('add_to', 'remove_from'));
        } else {
            
            if(this.id.indexOf('remove_link') != -1) {
                $('#' + this.id.replace('link_', '')).attr('class', 'add');
            }
        
            $(this).parent().attr('class', 'add');
            $(this).attr('href', $(this).attr('href').replace('remove_from', 'add_to'));
        }
        $(this).fadeOut();
        $(this).fadeIn();
       
        return false;
    }); 
    
    $('a.cart_remove_link').live('click', function(){        
       
        $.ajax({ url: $(this).attr('href'), context: document.body, success: function(){                        
            $('#cartinfo').load(window.location.href.replace('cart', 'cart/mini_cart')); 
            $('#sc').load(window.location.href.replace('cart', 'cart/cart_ajax')); 
            $('#cartinfo').fadeOut();           
            $('#cartinfo').fadeIn();
            $('#cart_holder').fadeOut();           
            $('#cart_holder').fadeIn();
        }});
        
        $(this).fadeOut();
        $(this).fadeIn();
       
        return false;
    });
    
       
    function cart_after(){
        $('#cartinfo').load(window.location.href.replace('cart', 'cart/mini_cart')); 
        $('#sc').load(window.location.href.replace('cart', 'cart/cart_ajax')); 
        $('#cartinfo').fadeOut();           
        $('#cartinfo').fadeIn();
        $('#cart_holder').fadeOut();           
        $('#cart_holder').fadeIn(); 
    }
    
    var cart_options = {    
        //beforeSubmit:   cart_before,
        success:        cart_after
    }
    $('.cart_form').ajaxForm(cart_options);
    
    
    //function small_before(){}
    
    function small_after(){
        $('#cartinfo').load(window.location.href.replace('search/products', 'cart/mini_cart')); 
        $('#search_cart').load(window.location.href.replace('search/products', 'cart/search_cart')); 
        $('#cartinfo').fadeOut();           
        $('#cartinfo').fadeIn();
        $('#search_cart').fadeOut();           
        $('#search_cart').fadeIn();
    }
    
    var small_cart_options = {    
        //beforeSubmit:   small_before,
        success:        small_after
    }    
    $('.small_cart_form').ajaxForm(small_cart_options);      
      
    function calculate(bnt_id){	    	  		  		  	
    val = typeof(val) != 'undefined'     ?   val : parseInt($('#summary .summary .number').html().replace(' t', ''));
    val_1 = typeof(val_1) != 'undefined' ? val_1 : parseInt($('#summary .car .number').html().replace(' t', ''));
    val_2 = typeof(val_2) != 'undefined' ? val_2 : parseInt($('#summary .home .number').html().replace(' t', ''));
    val_3 = typeof(val_3) != 'undefined' ? val_3 : parseInt($('#summary .flight .number').html().replace(' t', ''));	  	
    switch(bnt_id) {				
		    case 'v1':
			    val = val - val_1;
			    val_1 = 0;
			    ajax_calculate('vehicle', val_1);
		    break;
		    case 'v2':
			    val = val + 3;
			    val_1 = val_1 + 3;
			    ajax_calculate('vehicle', val_1);
			    ajax_calculate('motorbikes', 3);			    					
		    break;
		    case 'v3':
			    val = val + 4;
			    val_1 = val_1 + 4;
			    ajax_calculate('vehicle', val_1);
			    ajax_calculate('compacts', 4);					
		    break;				
		    case 'v4':
			    val = val + 6;
			    val_1 = val_1 + 6;
			    ajax_calculate('vehicle', val_1);
			    ajax_calculate('sedans', 6);					
		    break;
		    case 'v5':
			    val = val + 8;
			    val_1 = val_1 + 8;
			    ajax_calculate('vehicle', val_1);
			    ajax_calculate('suvs', 8);
		    break;
		    case 'v6':
			    val = val + 8;
			    val_1 = val_1 + 8;
			    ajax_calculate('vehicle', val_1);
			    ajax_calculate('trucks', 8);
		    break;
		    case 'h1':
			    val = val - val_2;
			    val_2 = 0;
			    ajax_calculate('home', val_2);
		    break;
		    case 'h2':
			    val = val + 4;
			    val_2 = val_2 + 4;
			    ajax_calculate('home', val_2);
			    ajax_calculate('persons', 4);
		    break;
		    case 'h3':
			    val = val + 8;
			    val_2 = val_2 + 8;
			    ajax_calculate('home', val_2);
			    ajax_calculate('persons', 8);
		    break;
		    case 'h4':
			    val = val + 16;
			    val_2 = val_2 + 16;
			    ajax_calculate('home', val_2);
			    ajax_calculate('persons', 16);
		    break;
		    case 'h5':
			    val = val + 24;
			    val_2 = val_2 + 24;
			    ajax_calculate('home', val_2);
			    ajax_calculate('persons', 24);
		    break;
		    case 'h6':
			    val = val + 36;
			    val_2 = val_2 + 36;
			    ajax_calculate('home', val_2);
			    ajax_calculate('persons', 36);
		    break;
		    case 'f1':
			    val = val - val_3;
			    val_3 = 0;
			    ajax_calculate('flight', val_3);
		    break;
		    case 'f2':
			    val = val + 1;
			    val_3 = val_3 + 1;
			    ajax_calculate('flight', val_3);
			    ajax_calculate('helicopters', 1);
		    break;
		    case 'f3':
			    val = val + 3;
			    val_3 = val_3 + 3;
			    ajax_calculate('flight', val_3);
			    ajax_calculate('short_flights', 3);
		    break;
		    case 'f4':
			    val = val + 6;
			    val_3 = val_3 + 6;
			    ajax_calculate('flight', val_3);
			    ajax_calculate('regional_flights', 6);
		    break;
		    case 'f5':
			    val = val + 10;
			    val_3 = val_3 + 10;
			    ajax_calculate('flight', val_3);
			    ajax_calculate('international_flights', 10);
		    break;
		    case 'f6':
			    val = val + 20;
			    val_3 = val_3 + 20;
			    ajax_calculate('flight', val_3);
			    ajax_calculate('intercontinental_flights', 20);
		    break;
		    default:
			    val = val
		    break;
	    }
	    $('#vehicle-calc .show_value').html('<span class="all">' + val + ' t</span> <strong class="explicit">'+ val_1 +' t</strong>');
	    $('#home-calc .show_value').html('<span class="all">' + val + ' t</span> <strong class="explicit">'+ val_2 +' t</strong>');
	    $('#flight-calc .show_value').html('<span class="all">' + val + ' t</span> <strong class="explicit">'+ val_3 +' t</strong>');
	
	    $('#summary .car .number').html(val_1 + ' t');
	    $('#summary .home .number').html(val_2 + ' t');
	    $('#summary .flight .number').html(val_3 + ' t');
	    $('#summary .summary .number').html(val + ' t');			
	    $('#summary .text-box strong').html(val + ' tones');
	
	    $('#cut-number').html(val + ' t');
	    $('.sin').html(val + ' t');
			      	
    }

    function ajax_calculate(type, value) {
        $.get(window.location + "calculator/calculate/?" + type + '=' + parseInt(value));
    } 
	  
	  		
	});
   /*
   var helvetica = { src: 'flash/helvetica.swf',ratios: [7, 1.32, 11, 1.31, 13, 1.24, 14, 1.25, 19, 1.23, 27, 1.2, 34, 1.19, 42, 1.18, 47, 1.17, 48, 1.18, 69, 1.17, 74, 1.16, 75, 1.17, 1.16]};
    sIFR.activate(helvetica);
    sIFR.replace ( helvetica, { selector: '#vehicle-calc .show_value .explicit' ,css: [ '.sIFR-root { font-size: 25px; color: #78a82b; text-align: right; }' ] ,wmode: 'transparent'  } );
    sIFR.replace ( helvetica, { selector: '#home-calc .show_value .explicit' ,css: [ '.sIFR-root { font-size: 25px; color: #ff5300; text-align: right; }' ] ,wmode: 'transparent'  } );    
    sIFR.replace ( helvetica, { selector: '#flight-calc .show_value .explicit' ,css: [ '.sIFR-root { font-size: 25px; color: #2b77a6; text-align: right; }' ] ,wmode: 'transparent'  } );     
    sIFR.replace ( helvetica, { selector: '#vehicle-calc .show_value .all' ,css: [ '.sIFR-root { font-size: 14px; color: #7C7C7D; text-align: center; }' ] ,wmode: 'transparent'  } );
    sIFR.replace ( helvetica, { selector: '#home-calc .show_value .all' ,css: [ '.sIFR-root { font-size: 14px; color: #7C7C7D; text-align: center; }' ] ,wmode: 'transparent'  } );    
    sIFR.replace ( helvetica, { selector: '#flight-calc .show_value .all' ,css: [ '.sIFR-root { font-size: 14px; color: #7C7C7D; text-align: center; }' ] ,wmode: 'transparent'  } ); 
    sIFR.replace ( helvetica, { selector: '#cut-number' ,css: [ '.sIFR-root { font-size: 25px; color: #ffffff; text-align: center; }' ] ,wmode: 'transparent'  } );     
    */
