var story_autoplay=false;
var curves=3;

initCufon();

$(document).ready(function(){
	
	initAddress();
	
	initForms();
	initCustomers();
	
	initMenu();
	initBGBlack();
	initBGGrey();
	
	initHomeDocument();	
	initTopbar();
	
	initMailTo();
	
	initSplash();
	
	initIE7ZindexFIX();
	
	initHomeInstrumentsSlider();
	
	$.taconite.debug=true;
	
	$('body').ajaxStart( function(){
    $(this).addClass('ajaxLoading');
  } );
	$('body').ajaxComplete( function(){
    $(this).removeClass('ajaxLoading');
  } );
  
  initJobs();
  
});

$(window).load(function(){
	initHome();
	initInstrumentsDetail();
	initStories();
	
	
// 	$('#content_container').css('opacity', 1);
});

function initJobs()
{

  $('input#uploadcv').amaiFile();
  
  if ( typeof(form_feedback)!='undefined' )
  {
    if ( form_feedback )
    {
      //scrollto mail_form
      var scrollPos = $('#mail_form').offset().top;
      $("html, body").animate({scrollTop:scrollPos},{duration:300, ease:"easeOutExpo"});
      
      $(form_feedback).each( function(index, val){
        if ( val=='name' )
        {
          $('#form_name').addClass('error').prev('label').addClass('error').prev('span').addClass('obligated_star_error');
        }
        if ( val=='lname' )
        {
          $('#form_lname').addClass('error').prev('label').addClass('error').prev('span').addClass('obligated_star_error');
        }
        if ( val=='email' )
        {
          $('#form_mail').addClass('error').prev('label').addClass('error').prev('span').addClass('obligated_star_error');
        }
        if ( val=='vacancy' )
        {
          $('#reason').addClass('error').prev('span').addClass('obligated_star_error')
          $('#reason').next('.select').addClass('error');
        }
        if ( val=='message' )
        {
          $('#form_message').addClass('error').prev('label').addClass('error').prev('span').addClass('obligated_star_error');
        }
        if ( val=='send' )
        {
          $('span.form_send').fadeIn('slow');
          setTimeout('clearJobForm();', 3000);
        }
      } );
    
    }
  }

}

function clearJobForm()
{
  $('span.form_send').fadeOut('slow');
  $('#form_name, #form_lname, #form_mail, #reason, #form_message').val('').trigger('blur');
  $('#reason').trigger('optionsChanged');
}

function initMenu(){


// 	for(var i = 1; i < 81; i++){
// 		var voorloopnul = "";
// 		if(i<10)
// 			voorloopnul = "0";
// 		var img = $("<img src='"+base_url+"media/img/bg_red/bg_red_" + voorloopnul + "" + i + ".png' />");
// 		$("#menu_image").append(img);
// 	}
// 	$("#menu_container img").css("max-height", $(window).height() + "px");

//   rpRed();

	$(window).resize(function(){$("#menu_container img").css("max-height", $(window).height() + "px");});
	if (jQuery.browser.msie) {
		$("#menu_container").css("position", "absolute");
		$(window).scroll(function(){
			//$("#menu_container").css("top", $(document).scrollTop() + "px");
		});
	}
	$(".internal_link").click(function(e){		
    var scrollPos = 0;    
    if ( $($(this).attr("rel")).length!=0 )
    {
      //element exists
      e.preventDefault();
      var rel=$(this).attr('rel');
      if ( rel=='#instruments_title' )
      {
        scrollPos = parseInt($(rel).offset().top)-190;
      }
      else if ( rel.indexOf('vacancy') )
      {
        scrollPos = parseInt($(rel).offset().top)-177;
      }
      else
      {
        scrollPos = $(rel).offset().top;
      }
      
      $("html, body").animate({scrollTop:scrollPos},{duration:300, ease:"easeOutExpo"});
    }
    else if ( $(this).hasClass("gototop") )
    {
      e.preventDefault();
      $("html, body").animate({scrollTop:scrollPos},{duration:300, ease:"easeOutExpo"});
    }
     
  });
	
	$('#submenu li').click( function() {    
    if ( $($(this).children('a').attr("rel")).length!=0 )
    {
      $('#submenu li').removeClass('active');
      $(this).addClass('active');
    }
  } );
}

function initBGBlack(){
// 	var img;
//   for(var i = 1; i < 27; i++){
// 		var voorloopnul = "";
// 		if(i<10)
// 			voorloopnul = "0";
// 		img = $("<img src='"+base_url+"media/img/bg_black/bg_black_" + voorloopnul + "" + i + ".png' style='display: none;' />");
// 		$("#bg_right").append(img);
// 		img.load(function(){			
//       $(this).css("margin-top", - $(this).height());
// 			if(jQuery.browser.msie && parseInt($.browser.version.substr(0,1)) == 8){
// 				$(this).css("position", "absolute");
// 			}
// 			if(!jQuery.browser.msie || (jQuery.browser.msie && parseInt($.browser.version.substr(0,1)) > 7)){
// 				$(this).css("margin-left", $(this).index() * 20 + "px");
// 			}
// 		});		
// 	}
// 	$('#bg_right img').css('display', 'block');
    
//     rpBlack();
}

function initBGGrey(){
// 	for(var i = 1; i < 42; i++){
// 		var voorloopnul = "";
// 		if(i<10)
// 			voorloopnul = "0";
// 		var img = $("<img src='"+base_url+"media/img/bg_grey/bg_red_" + voorloopnul + "" + i + ".png' />");
// 		$("#bg_left").append(img);
// 		img.load(function(){
// 			$(this).css("margin-top", - $(this).height() + "px");
// 			if(!jQuery.browser.msie || (jQuery.browser.msie && parseInt($.browser.version.substr(0,1)) > 7)){
// 				$(this).css("margin-left", $(this).index() * 20 + "px");
// 			}
// 		});
// 	}
//   rpGrey();
}

function initCufon(){
	Cufon.replace("#menu li a", {hover:true, fontFamily: 'Graphik'});
	Cufon.replace("h2, h3", {fontFamily: 'Graphik'});
	Cufon.replace("#baseline, .story_title, .keepwhite, #download_table th .title, #driver_table th .title, #faq_list>dt span, .qnum", {fontFamily: 'Archer'});
	Cufon.replace("#driver_table a", {fontFamily: 'Archer', hover:true});
  
  Cufon.replace("#faq_list > dt a", {fontFamily: 'Archer', hover:true});
	Cufon.replace("#numweeks, #numweekstext", {fontFamily: 'ArcherBold'});
	Cufon.replace("#splash_container .left a", {hover:true, fontFamily: 'Graphik'});
	
	Cufon.replace("#vacancy_description h4", {fontFamily: 'Graphik'});
	
	Cufon.replace("#contact_main_text h4", {fontFamily: 'Archer'});
}

function initForms(){
	$("select").each(function(){
		if(!$(this).hasClass("special")){
			if ( $(this).hasClass('instruments') ) {
		    $(this).amaiSelect(100, 268, "select", true, true);
      }
      else
      {
        $(this).amaiSelect(100, 134, "select", true, true);
      }
		} else { 
			$(this).amaiSelect(100, 134, "specialSelect", true, true);
		}
	});
	
	$('#idea_form input[type=radio]').amaiRadio();
	$('#question_form input[type=radio]').amaiRadio();
	$('#top input[type=checkbox]').amaiCheck();
	
	if($("#mail_form").size()){
		$("#mail_form input, #mail_form textarea").each(function(){
			if($(this).val() != ""){
				$(this).parent().children("label").hide();
			}
		});
		$("#mail_form input, #mail_form textarea").focus(function(){
			$(this).parent().children("label").hide();
		});
		$("#mail_form input, #mail_form textarea").blur(function(){
			if($(this).val() == ""){
				$(this).parent().children("label").show();
			}
		});
		
	}
	
	$("#socialbar input").focus(function(){
			$(this).parent().children("label").hide();
		}).blur(function(){
			if($(this).val() == ""){
				$(this).parent().children("label").show();
			}
		});
	
	$("#feedbackbar input, #feedbackbar textarea").focus(function(){
			$(this).parent().children("label").hide();
		}).blur(function(){
			if($(this).val() == ""){
				$(this).parent().children("label").show();
			}
		});
	
	$('#feedbackbar textarea').amaiTextareaLimit();
}

/*

SEPERATE PAGES

*/

function initHomeDocument(){
	$(".stories a .story_title").css({height:0, marginTop:82, paddingTop:0, paddingBottom:0, border:0, opacity:1});
	$(".stories a").hover(function(){
		$(this).find(".story_title").stop();
		$(this).find(".story_title").animate({height:85, marginTop:0, paddingTop:40, paddingBottom:40}, {duration:100, easing:"easeOutExpo"});
	}, function(){
		$(this).find(".story_title").animate({height:0, marginTop:82, paddingTop:0, paddingBottom:0, border:0}, {duration:700, easing:"easeOutExpo"});
	});
}

function initHomeInstrumentsSlider()
{
//       var sum = 0;
//   		var ul = $("#instruments");  		
//   		ul.children('li').each(function(){
//   			sum += $(this).width() + 80;
//   		});


    
//     ul.find('li img').bind('load', function(){
//               	sum=0;
//                 ul.children('li').each(function(){
//             			sum += $(this).width() + 80;
//             		});
//                 		ul.width(sum);
//           		ul.children('li:last-child').css("margin-right", "0px");
//           		ul.children('li:first-child').css("margin-left", "0px");
//         
//           	var slidePos=0;
//           	var slideDisabled=false;
//           	scrollContent = ul;
//           	if ( scrollContent.width() < 950 ) {
//           	 scrollContent.css( 'left', ((950/2)-(scrollContent.width()/2)) );
//           	 slidePos=50;
//           	 slideDisabled=true;
//             }
//           		//build slider
//           		
//       
//     } );

  var slidePos=0;
  var slideDisabled=false;
  var scrollbar = $( "#scrollbar" ).slider({
          			value: slidePos,
          			disabled: slideDisabled,
                slide: function( event, ui ) {
                
                    var sum = 0;
                		var ul = $("#instruments");  		
                		ul.children('li').each(function(){
                			sum += $(this).width() + 80;
                		});
                    if ( sum > 950 )
                    {
                      ul.animate({left:-1*(sum - 950) * ui.value / 100},{duration:600, queue:false, easing:"easeOutExpo"});
                    }else
                    {
                      scrollbar.slider( { disabled: true } );
                    }  					
          			}});
          			
  var itemCount=$("#instruments li").length;
  var loaded=0;
  var loadedSum=0;
  /* $("#instruments li img").one('load', function(){
    loaded++;
    loadedSum+=$(this).width();
    if ( loaded==itemCount )
    {
      if ( loadedSum<950 )
      {
    	  $("#scrollbar .ui-slider-handle").css("opacity", "0");
    	  scrollbar.slider( { disabled: true } );
      } else {
    	  $("#scrollbar .ui-slider-handle").css("opacity", "1");
    	  scrollbar.slider( { disabled: false } );
      }
    }
  } );
	*/
  
  $("#instruments li img").each(function(){
	  loadedSum += $(this).attr("width");
  });
  if ( loadedSum<950 )
  {
	  $("#scrollbar .ui-slider-handle").css("visibility", "hidden");
	  scrollbar.slider( { disabled: true } );
  } else {
	  $("#scrollbar .ui-slider-handle").css("visibility", "visible");
	  scrollbar.slider( { disabled: false } );
  }
}

function initStories()
{
  
  if ( $('#stories_container').size() )
  {    
    $('#select_story').change( function(e) {
//       document.location.href=base_url+'stories/'+$(this).val();
        var story_id=$(this).val();
        $('.videoslider .videoslider_item').each( function() {
          var $this = $(this);
          var link =$this.children('a'); 
          if (link.attr('rel')==story_id)
          {
            story_autoplay=true;
            link.trigger('click');
          } 
        } );
    });
  $('.videoslider').videoslider();
  }

}

function initHome(){
	if($("#content_home").size()){
		
// 		initHomeInstrumentsSlider();
		
    
    $('#menu_instruments a.btn').click( function(e) {
      e.preventDefault();
      var cat_id=$(this).attr('rel');      
        $.ajax({
          type: 'POST',
          url: base_url+'etc/home_get_category_products',
          data: { category_id: $(this).attr('rel') },
          success: function() { 
            $('#instruments_ddl').val(0);
            $('#instruments_ddl').trigger('optionsChanged');
          }
        });      
    });
    
    $('#instruments_ddl').change( function(e){
      $.ajax({
        type: 'POST',
        url: base_url + 'etc/home_get_category_products',
        data: { category_id: $(this).val() }
      });
    });
    
    $('#select_profile').change( function(e) {
      document.location.href=base_url+'profile/'+$(this).val();
    });   
		
		//stories
		var teller = 0;
		$(".stories").each(function(){
			var sum_stories = 0;
			$(this).children("li").each(function(){
				sum_stories += $(this).width() + 80;
			});
// 			sum_stories = sum_stories-80;
			$(this).width(sum_stories);
			$(this).css("margin-top", (teller * 165) + "px");
			teller++;
		});
		$("#stories_height").height(teller * 165);
		$(".stories").mousemove(function(e){
			var $this=$(this);
      var sum_stories = 0;
			$this.children("li").each(function(){
				sum_stories += $(this).width();
			});
			sum_stories = sum_stories;
			
      var val = (-1*(sum_stories - $(window).width()) * (1-(($(window).width() - e.pageX) / $(window).width())))-80;

			$(this).animate({left:val},{duration:600, queue:false, easing:"easeOutExpo"});
		});

	}
}

function initInstrumentsDetail(){
	if($("#instrument_pictures").size()){
		repositionImages();
    	$(window).resize(repositionImages);
	}
	if($("#instrument_pictures, #instrument_image").size()){
		initCalculator();
		
		$('#instrument_type').change( function() {
			document.location.href=base_url+'instruments/'+$(this).val();
		});
    
		$('#payback_calculator').trigger('change');
	}
}

	function repositionImages(){
		var sum = 0;
		$("#instrument_pictures li").each(function(){
			sum += $(this).width();
		});
		$("#instrument_pictures").width(sum);
		if($("#instrument_pictures").width() > $(window).width()){
			$("#instrument_pictures").mousemove(function(e){
				var val = -1*(sum - $(window).width()) * (1-(($(window).width() - e.pageX) / $(window).width()));
				$(this).stop();
				$(this).animate({left:val},{duration:600, queue:false, easing:"easeOutExpo"});
			});
		} else {
			$("#instrument_pictures").unbind("mousemove");
		}
		
		var val=($(window).width()-sum)/2;
    	$("#instrument_pictures").animate({left:val},{duration:0, queue:false, easing:"easeOutExpo"});
	}

	function initCalculator(){
		if ($("#payback_calculator").length!=0)
		{
      if($("#payback_calculator").hasClass("beer")){
          var action = calcBeer;
  		} else if($("#payback_calculator").hasClass("wine")){
  			var action = calcWine;
  		} else if($("#payback_calculator").hasClass("alcohol")){
  			 var action = calcAlcohol;
  		} else if($("#payback_calculator").hasClass("units")){
  			 var action = calcUnits;
  		} else if($("#payback_calculator").hasClass("unitsHot")){
  			 var action = calcUnitsHot;
  		}
  		$('#payback_calculator').bind('change', action);
  		$('#payback_calculator input[type=text]').live('keyup', action);
  		$('#payback_calculator #intoaccount_container select').live('change', action);
  
      $('#payback_calculator a.add_row').click( function(e) {
        e.preventDefault();
        var newrow=$('#turnover > li:last-child').clone();
        newrow.find('div.select').remove();
        newrow.appendTo('#turnover');
        newrow.find('select').amaiSelect(100, 134, "select", true, true);
        newrow.find('.remove_row').remove();
        newrow.append('<a href="#" class="remove_row">remove row</a>');
        newrow.children('a.remove_row').click( function(e) {
          e.preventDefault();
          $(this).parent('li').remove();
          $('#payback_calculator').trigger('change');
        } );
        $('#payback_calculator').trigger('change');
      } );
      
	  }
  }
	
	var calcBeer = function(){
// 		console.log('calBeer');
		var totalPaybackWeeks=0;
    var totalProfit=0;
    var profitWeek;
    
    $('#turnover>li').each( function(index) {
      var row=$(this);
      
      var amount = parseInt(row.find('input[name=amount]').val());
      var size = parseInt(row.find('select[name=size]').val());
      var unitPrice = parseFloat(row.find('input[name=price]').val());
      
      unitPrice = isNaN(unitPrice) ? 0 : unitPrice;
      amount = isNaN(amount) ? 0 : amount;
      
      var theft = (parseInt($('#theft').val())/100);
      var free = (parseInt($('#free').val())/100);
      var loss = (3/100);
      var overdosing = (parseInt($('#overdosing').val())/100);
      
      //don't use loss because there will still be loss.
      var totalLoss = theft+free+loss;
      
      var units;
      var barrelPrice;
      switch (size)
      {
        case 20:
          units=69;
          barrelPrice=50;
        break;
        case 30:
          units=108;
          barrelPrice=70;
        break;
        case 50:
          units=180;
          barrelPrice=95;
        break;
        case 100:
          units=370;
          barrelPrice=170;
        break;
      }
      
      var totalPrice=unitPrice*(amount*units);      
      profitWeek=totalLoss*totalPrice;
      
      //calc profit for overdosing
      var overdoseProfit =  (amount*barrelPrice)*overdosing;
      
      profitWeek+=overdoseProfit; 
      
      var paybackWeeks=productPrice/profitWeek;
      
      totalProfit+=profitWeek;
      totalPaybackWeeks+=paybackWeeks;
      
    } );
    
    var rows=$('#turnover>li').length;
    var productsRequired=1*rows;
    
    if ( totalProfit==0 )
    {
      totalPaybackWeeks=0;
    }
    else
    {
      totalPaybackWeeks=(productPrice * productsRequired)/totalProfit;
    }    
    
    
    $('#numweeks').text(Math.round(profitWeek));
    Cufon.replace("#numweeks", {fontFamily: 'ArcherBold'});
    
    $('#calcProfit').text(Math.round(totalProfit));
	}
	
	var calcWine = function(){
// 		console.log('calWine');
		var totalPaybackWeeks=0;
    var profitWeek=0;
    var totalProfitWeek=0;
    
    $('#turnover>li').each( function(index) {
      var row=$(this);
      
      var amount = parseInt(row.find('input[name=amount]').val());      
      var unitPrice = parseFloat(row.find('input[name=price]').val());
      
      unitPrice = isNaN(unitPrice) ? 0 : unitPrice;
      amount = isNaN(amount) ? 0 : amount;
      
      var theft = (parseInt($('#theft').val())/100);
      var free = (parseInt($('#free').val())/100);
      var loss = (parseInt($('#loss').val())/100);
      var spill = (3/100);
      
      //don't use loss because there will still be loss.
      var totalLoss = theft+free+spill;
      
      var units;
      var barrelPrice;
//       switch (size)
//       {
//         case 0.75:
//           units=14;
//           barrelPrice=50;
//         break;        
//       }
      units=5.5;
      var barrelPrice=5;
      
      var totalPrice=unitPrice*(amount*units);      
      profitWeek=totalLoss*totalPrice;
      
//       var paybackWeeks=productPrice/profitWeek;
//       paybackWeeks = ( profitWeek==0 ) ? 0 : paybackWeeks;
//       totalPaybackWeeks+=paybackWeeks;
      
      totalProfitWeek+=profitWeek;
    } );
    
    var rows=$('#turnover>li').length;
    var productsRequired=1;
    productsRequired=Math.ceil(rows/2);    
   
    if ( totalProfitWeek==0 )
    {
      totalPaybackWeeks=0;
    }
    else
    {
      totalPaybackWeeks=(productPrice * productsRequired)/totalProfitWeek;
    }
    
    
    $('#numweeks').text(Math.round(totalProfitWeek));
    Cufon.replace("#numweeks", {fontFamily: 'ArcherBold'});
		
		$('#calcProfit').text(Math.round(totalProfitWeek));
	}
	
	var calcAlcohol = function(){
//     console.log('calAlcohol');
		var totalPaybackWeeks=0;
    var profitWeek=0;
    var totalProfitWeek=0;
    $('#turnover>li').each( function(index) {
      var row=$(this);
      
      var amount = parseInt(row.find('input[name=amount]').val());
      var size = parseFloat(row.find('select[name=size]').val());
      var unitPrice = parseFloat(row.find('input[name=price]').val());
      
      unitPrice = isNaN(unitPrice) ? 0 : unitPrice;
      amount = isNaN(amount) ? 0 : amount;
      
      var theft = (parseInt($('#theft').val())/100);
      var free = (parseInt($('#free').val())/100);
      var loss = (3/100);
      var spill = (parseInt($('#overdosing').val())/100);
      
      //don't use loss because there will still be loss.
      var totalLoss = theft+free+spill;
      
      var units;
      var barrelPrice;
      switch (size)
      {
        case 0.75:
          units=14;
          barrelPrice=9;
        break;        
      }
      
      var totalPrice=unitPrice*(amount*units);      
      profitWeek=totalLoss*totalPrice;
      
//       var paybackWeeks=productPrice/profitWeek;
//       paybackWeeks = ( profitWeek==0 ) ? 0 : paybackWeeks;
//       totalPaybackWeeks+=paybackWeeks;
      
      totalProfitWeek+=profitWeek;      
    } );
    
    var rows=$('#turnover>li').length;
    var productsRequired=1;
    switch( productName )
    {
      case 'Non Drip':  
      case 'Speedrail':      
        productsRequired=Math.ceil(rows/8);        
      break;
    }
    
    if ( totalProfitWeek==0 )
    {
      totalPaybackWeeks=0;
    }
    else
    {
      totalPaybackWeeks=(productPrice * productsRequired)/totalProfitWeek;
    }
    
    
    $('#numweeks').text(Math.round(totalProfitWeek));
    Cufon.replace("#numweeks", {fontFamily: 'ArcherBold'});
		
		$('#calcProfit').text(Math.round(totalProfitWeek));
	}
	
	var calcUnits = function(){
//     console.log('calUnits');
		var totalPaybackWeeks=0;
    var profitWeek=0;
    var totalProfitWeek=0;
    $('#turnover>li').each( function(index) {
      var row=$(this);
      
      var amount = parseInt(row.find('input[name=amount]').val());
//       var size = parseFloat(row.find('select[name=size]').val());
      var unitPrice = parseFloat(row.find('input[name=price]').val());
      
      unitPrice = isNaN(unitPrice) ? 0 : unitPrice;
      amount = isNaN(amount) ? 0 : amount;
      
      var theft = (parseInt($('#theft').val())/100);
      var free = (parseInt($('#free').val())/100);
      var loss = (3/100);
      var spill = (parseInt($('#overdosing').val())/100);
      
      //don't use loss because there will still be loss.
      var totalLoss = theft+free+spill;
      
      var units;
      var barrelPrice;
//       switch (size)
//       {
//         case 0.75:
//           units=14;
//           barrelPrice=9;
//         break;
//       }
      units = 1;
      barrelPrice=0.5;
      
      var totalPrice=unitPrice*(amount*units);      
      profitWeek=totalLoss*totalPrice;
      
//       var paybackWeeks=productPrice/profitWeek;
//       paybackWeeks = ( profitWeek==0 ) ? 0 : paybackWeeks;
//       totalPaybackWeeks+=paybackWeeks;
      
      totalProfitWeek+=profitWeek; 
      
    } );
    
    var rows=$('#turnover>li').length;
    var productsRequired=1;
    productsRequired=Math.ceil(rows/8);
   
    if ( totalProfitWeek==0 )
    {
      totalPaybackWeeks=0;
    }
    else
    {
      totalPaybackWeeks=(productPrice * productsRequired)/totalProfitWeek;
    }
    
    $('#numweeks').text(Math.round(totalProfitWeek));
    Cufon.replace("#numweeks", {fontFamily: 'ArcherBold'});
    
    $('#calcProfit').text(Math.round(totalProfitWeek));
		
	}
	
		var calcUnitsHot = function(){
//     console.log('calUnits');
		var totalPaybackWeeks=0;
    var profitWeek=0;
    var totalProfitWeek=0;
    $('#turnover>li').each( function(index) {
      var row=$(this);
      
      var amount = parseInt(row.find('input[name=amount]').val());
//       var size = parseFloat(row.find('select[name=size]').val());
      var unitPrice = parseFloat(row.find('input[name=price]').val());
      
      unitPrice = isNaN(unitPrice) ? 0 : unitPrice;
      amount = isNaN(amount) ? 0 : amount;
      
      var theft = (parseInt($('#theft').val())/100);
      var free = (parseInt($('#free').val())/100);
      var loss = (3/100);
      var spill = (parseInt($('#overdosing').val())/100);
      
      //don't use loss because there will still be loss.
      var totalLoss = theft+free+spill;
      
      var units;
      var barrelPrice;
//       switch (size)
//       {
//         case 0.75:
//           units=14;
//           barrelPrice=9;
//         break;
//       }
      units = 1;
      barrelPrice=0.5;
      
      var totalPrice=unitPrice*(amount*units);      
      profitWeek=totalLoss*totalPrice;
      
//       var paybackWeeks=productPrice/profitWeek;
//       paybackWeeks = ( profitWeek==0 ) ? 0 : paybackWeeks;
//       totalPaybackWeeks+=paybackWeeks;
      
      totalProfitWeek+=profitWeek; 
      
    } );
    
    var rows=$('#turnover>li').length;
    var productsRequired=1;
    productsRequired=Math.ceil(rows/5);
   
    if ( totalProfitWeek==0 )
    {
      totalPaybackWeeks=0;
    }
    else
    {
      totalPaybackWeeks=(productPrice * productsRequired)/totalProfitWeek;
    }
    
    $('#numweeks').text(Math.round(totalProfitWeek));
    Cufon.replace("#numweeks", {fontFamily: 'ArcherBold'});
    
    $('#calcProfit').text(Math.round(totalProfitWeek));
		
	}

function initCustomers(){
	if($("#faq_list").size()){
		$("#faq_list dd dd").hide();
		$("#faq_list dd dl").hide();
		$("#faq_list dd dl:first-child").show();
		$("#faq_list dd dt a").click(function(e)
    {
			e.preventDefault();
			if ( $(this).hasClass('active') )
			{
        $(this).parent().next().slideUp(200);
        $(this).removeClass('active');
      }
      else
      {
        $("#faq_list dd dt a").parent().next().slideUp(200);
        $("#faq_list dd dt a").removeClass("active");
  			$(this).addClass("active");
  			$(this).parent().next().slideDown(200);
			}
		});
		$("#faq_list > dt").each(function(){
			$(this).children("a:first").addClass("active")
		});
		$("#faq_list > dt a").click(function(){
			var toOpen = $($(this).attr("href"));
			$(this).parent().next().children().each(function(){
				if($(this).attr("id") == toOpen.attr("id")){
					if($(this).is(":hidden")){
						$(this).slideDown(200, function(){
							if($.browser.msie){
								Cufon.replace(".qnum", {fontFamily: 'Archer'});
								$(this).find(".qnum cufon cufoncanvas").show();
							}
						});
					} else {
						$(this).slideUp(200);
					}
				} else {
					$(this).slideUp(200);
				}
			});
			$(this).parent().children("a").removeClass("active");
			$(this).addClass("active");
			Cufon.refresh("#faq_list > dt a");
			
			return false;
		});
	}
	
  $('#download_table select, #driver_table select').change( function() {
    if ( $(this).parents('tr').hasClass('drivers') )
    {
      var newWindow = window.open($(this).val(), 'Driver' );
    }
    else
    {
      var newWindow = window.open(base_url+'download/'+$(this).val()+'.pdf', 'Manual' );
    }    
    newWindow.focus();
  } );
	
}


$.fn.updateHomeInstrumentsSlider = function(data) {

  $(this).html(data);
  initHomeInstrumentsSlider();
}

$.fn.showProduct = function (productId) {
  document.location.href=base_url+'instruments/'+productId;
}
$.fn.showProductCalculator = function (productId) {
  document.location.href=base_url+'instruments/'+productId+'#payback_calculator';
}

function gotoProduct(prod)
{
  $.ajax({
        type: 'POST',
        url: base_url+'etc/flash_gotoProduct',
        data: { prod: prod }
      });
}

function gotoCalculator(prod)
{
  $.ajax({
        type: 'POST',
        url: base_url+'etc/flash_gotoCalculator',
        data: { prod: prod }
      });
}

$.fn.videoslider = function()
{
  var container = this;
  var items = container.children('.videoslider_item');  
  
  var totalWidth=0;
  items.each( function() {
    totalWidth+=$(this).width();
  } );
  
  container.css({ position: 'absolute',
                  width: totalWidth,
                  overflow: 'hidden' });
  items.css( { float: 'left' } );
  
  var containerHeight = container.height();
  var containerWidth = totalWidth;
           
  //put in spacefiller
  container.after('<div id="videoslider_spacefiller"></div><a class="video_left" href="#">left</a><a class="video_right" href="#">right</a>');
  var spacefiller=$('#videoslider_spacefiller');
    
//   var availableWidth = spacefiller.width();
//   var defaultPositionLeft=((((containerWidth-availableWidth)/2)*-1)-79);
//   container.css({ left: defaultPositionLeft });
  
  story_autoplay=true;
  set_active_item();
  
  $('a.video_left').click( function(e) {
    e.preventDefault();
    items.each( function() {
      var link = $(this).children('a');
      if ( link.hasClass('active') )
      {
        if ( $(this).prev().length!=0 )
        {
          link.removeClass('active');
          $(this).prev().children('a').addClass('active');
          set_active_item();
          return false;
        }
      }
    } );
  } );
  
  $('a.video_right').click( function(e) {
    e.preventDefault();
    items.each( function() {
      var link = $(this).children('a');
      if ( link.hasClass('active') )
      {
        if ( $(this).next().length!=0 )
        {
          link.removeClass('active');
          $(this).next().children('a').addClass('active');
          set_active_item();
          return false;
        }
      }
    } );
  } );
  
  items.children('a').click( function(e) {
    e.preventDefault();
    items.children('a').removeClass('active');    
    $(this).addClass('active');
    set_active_item();
  } );

  
  function set_active_item()
  {
    $('#story_flashplayer').remove();
    var activePosition;    
    items.each( function() {
      $this=$(this);
      if ( $this.children('a').hasClass('active') )
      {
        var id=$this.children('a').attr('rel');
        $this.animate({opacity: 1});
        activePosition=$this.position();
        $this.append('<div id="story_flashplayer"></div>');
        load_story( id );
        $('#select_story').val( id );
        $('#select_story').trigger('optionsChanged');
      }
      else
      {
        $this.animate({opacity: 0.5});
      }
    });    
    var moveLeft=(activePosition.left*-1)+159;
    container.animate( {left: moveLeft}, {duration: 600, easing: 'easeOutExpo', complete: function(){

    } });
  }
  
  function load_story(id)
  {
    var flv=false;
    var thumb;
    var title;
    var description;
    
    /*
    $(stories).each( function(index, obj) {
      if ( parseInt(obj.id)==id )
      {
        flv=obj.video;
        thumb=obj.image;
        title=obj.title;
        description=obj.description;
        print_pdf=obj.print_pdf
        return false;
      }
    } );
    
    */
    
    flv=stories[id].video;
    thumb=stories[id].image;
    title=stories[id].title;
    description=stories[id].description;
    print_pdf=stories[id].print_pdf
    
    if ( flv )
    {
    	var flashvars = { file: base_url+"media/flash/"+flv, autoplay: 'false', skin:base_url+'media/flash/etc_skin.zip', 'controlbar.position':"over", "dock":"false"};
    	
    	if(stories[id].video_translation != ""){
    		flashvars["captions.file"] = base_url + "media/flash/translationxml/" + stories[id].video_translation;
    		flashvars["captions.fontsize"] = "10";
    		flashvars["plugins"] = "captions-1";
    	}
    	
    	if (story_autoplay) {
    		flashvars.autoplay = "true";
            story_autoplay=false;
        }
        
        var params = { scale:'noScale', salign:'lt', menu:'false', bgcolor:'#ffffff',allowScriptAccess:'always', wmode: 'transparent', allowFullScreen:'true' };
        var attributes = { };
      
        swfobject.embedSWF(base_url+'media/flash/player.swf','story_flashplayer','640','360','10.0.0',false, flashvars, params, attributes, flashLoaded);
        
        //player.controls.controlbar.hide()
        
        /*

    	var v = {};
        v.as_swf_name = "noF";    
        v.flv = base_url+"media/flash/"+flv;
        v.thumbnail = base_url+"upload/stories/image/"+thumb;
        if (story_autoplay) {
          v.autoplay  = "true";
          story_autoplay=false;
        }
        var p = { scale:'noScale', salign:'lt', menu:'false', bgcolor:'#ffffff',allowScriptAccess:'always', wmode: 'transparent', allowFullScreen:'true'};
        var a = {}
                		
        swfobject.embedSWF(base_url+"media/flash/FLVplayerWit.swf", "story_flashplayer", "640", "360", "10.0.0", false, v, p, a);
        
     */
    }
    var storywrapper = $('#story_wrapper');
    storywrapper.children('h3').text(title);
    storywrapper.children('div').html(description);
    Cufon.replace('#story_wrapper h3', {fontFamily: 'Graphik'});
  }
  
}

function flashLoaded(e){
	//console.log("flash loaded");
	//jwplayer(e.ref).getPlugin("dock").hide()
}

var topbartimer;

function initTopbar()
{
  $('#feedbackbar').tabs();
  
  $('#sharebtn, #feedbackbtn').click( function(e) {
    e.preventDefault();
    var topbar = $('#top');
    
    topbar.children('div').css('display', 'none');
    if ($(this).attr('rel')=='share')
    {
      topbar.children('div#socialbar').css('display', 'block');
    }
    if ($(this).attr('rel')=='feedback')
    {
      topbar.children('div#feedbackbar').css('display', 'block');
    }
    
    topbar.find('input[type=text]').val('').blur();
    topbar.animate( { top:0 }, { duration: 400,
                          easing: 'easeOutExpo' } )
          .addClass('visible');
    if ( ! $.browser.msie )
    {
    $('#container').animate( { marginTop: 150 },
                             { duration: 400,
                               easing: 'easeOutExpo' } );
    }
    topbartimer=$.timer(2000, function(timer) {
                   if (window.mouseYPos < topbar.height())
                   {                    
                    timer.reset(2000);
                   }
                   else
                   {
                    var focused=false;
                    topbar.find('input, textarea').each( function() {
                      if ( $(this).hasClass('focus') )
                      focused=true;
                    } );
                    if (focused)
                    {
                      timer.reset(2000);
                    }
                    else
                    {
//                       topbar.slideUp( 400, 'easeOutExpo' );
                      topbar.animate( { top:-150 }, { duration: 400,
                                                   easing: 'easeOutExpo' } )
                            .removeClass('visible');
                      $('#container').animate( { marginTop: 0 },
                             { duration: 400,
                               easing: 'easeOutExpo' } );
                      timer.stop();
                    }
                   }                    
                } );
  
  $(document).bind('scroll.topbar', function(){
      var topbar = $('#top');
      if ( topbar.hasClass('visible') )
      {
        topbar.animate( { top:-150 }, { duration: 400,
                                        easing: 'easeOutExpo' } )
              .removeClass('visible');
        $('#container').animate( { marginTop: 0 },
                                 { duration: 400,
                                   easing: 'easeOutExpo' } );
       topbartimer.stop();
       $(document).unbind('scroll.topbar');
      }
  } );
  
  
  } );
  
  $('#top input, #top textarea').focus( function() {
    $(this).addClass('focus');
    topbartimer.reset(2000);        
  } );
  
  $('#top input, #top textarea').blur( function() {
    $(this).removeClass('focus');            
  } );
  
  $('body').mouseover( function(e) {
      window.mouseXPos = e.pageX;
      window.mouseYPos = e.pageY;      
  } );
    
  
  $('#top_links a.print').click( function(e) {
    e.preventDefault();
    var newWindow = window.open(print_pdf, 'PDF' );    
    newWindow.focus();
  } );
  
  $('#topbarShareBtn').click( function(e) {
    e.preventDefault();
    $.ajax( { type: 'POST',
              url: base_url+'share',
              data: $('#topbarShareForm').serialize()              
              } );
  } );
  $('a.submit').click( function(e) {
    e.preventDefault();
    if ( ! $(this).hasClass('noajax') )
    {
      $.ajax( { type: 'POST',
                url: base_url+$(this).attr('rel'),
                data: $(this).parents('form').serialize()
                } );
    } else
    {
      $(this).parents('form').submit();
    }
  } );
  
}

$.fn.shareFormFeedback = function(feedback)
{
  $this=$(this);
  
  $this.find('label, input').removeClass('error');
  
  feedback=$.parseJSON(feedback);
    if ($.inArray( 'name', feedback )>-1)
    {
      $this.find('label[for=topbar_name]').addClass('error');
      $this.find('input#topbar_name').addClass('error');
    }
    if ($.inArray( 'email', feedback )>-1)
    {
      $this.find('label[for=topbar_email]').addClass('error');
      $this.find('input#topbar_email').addClass('error');
    }
    if ($.inArray( 'send', feedback )>-1)
    {
      $this.find('span.btn_feedback').next().css('display', 'none');
      $this.find('span.btn_feedback').css('display', 'block');
      setTimeout( function(){
        $this.find('span.btn_feedback').next().css('display', 'block');
        $this.find('span.btn_feedback').css('display', 'none');
        $this.find('input').val('').trigger('blur');
      }, 2000 );
    }
};

$.fn.ideaFormFeedback = function(feedback)
{
  $this=$(this);
  
  $this.find('label, input, textarea').removeClass('error');
  
  feedback=$.parseJSON(feedback);
    if ($.inArray( 'name', feedback )>-1)
    {
      $this.find('label[for=idea_name]').addClass('error');
      $this.find('#idea_name').addClass('error');
    }
    if ($.inArray( 'email', feedback )>-1)
    {
      $this.find('label[for=idea_email]').addClass('error');
      $this.find('#idea_email').addClass('error');
    }
    if ($.inArray( 'idea', feedback )>-1)
    {
      $this.find('label[for=idea_message]').addClass('error');
      $this.find('#idea_message').addClass('error');
    }
    if ($.inArray( 'send', feedback )>-1)
    {
      $this.find('span.btn_feedback').next().css('display', 'none');
      $this.find('span.btn_feedback').css('display', 'block');
      setTimeout( function(){
        $this.find('span.btn_feedback').next().css('display', 'block');
        $this.find('span.btn_feedback').css('display', 'none');
        $this.find('input[type=text], textarea').val('').trigger('blur').trigger('keyup');
        $this.find('input[type=radio]').attr('checked', false).next().removeClass('radioChecked');
      }, 2000 );
    }
};

$.fn.questionFormFeedback = function(feedback)
{
  $this=$(this);
  
  $this.find('label, input, textarea').removeClass('error');
  
  feedback=$.parseJSON(feedback);
    if ($.inArray( 'name', feedback )>-1)
    {
      $this.find('label[for=question_name]').addClass('error');
      $this.find('#question_name').addClass('error');
    }
    if ($.inArray( 'email', feedback )>-1)
    {
      $this.find('label[for=question_email]').addClass('error');
      $this.find('#question_email').addClass('error');
    }
    if ($.inArray( 'question', feedback )>-1)
    {
      $this.find('label[for=question_message]').addClass('error');
      $this.find('#question_message').addClass('error');
    }
    if ($.inArray( 'send', feedback )>-1)
    {
      $this.find('span.btn_feedback').next().css('display', 'none');
      $this.find('span.btn_feedback').css('display', 'block');
      setTimeout( function(){
        $this.find('span.btn_feedback').next().css('display', 'block');
        $this.find('span.btn_feedback').css('display', 'none');
        $this.find('input[type=text], textarea').val('').trigger('blur').trigger('keyup');
        $this.find('input[type=radio]').attr('checked', false).next().removeClass('radioChecked');
      }, 2000 );
    }
};

$.fn.hateFormFeedback = function(feedback)
{
  $this=$(this);
  
  $this.find('label, input, textarea').removeClass('error');
  
  feedback=$.parseJSON(feedback);
    if ($.inArray( 'name', feedback )>-1)
    {
      $this.find('label[for=hate_name]').addClass('error');
      $this.find('#hate_name').addClass('error');
    }
    if ($.inArray( 'email', feedback )>-1)
    {
      $this.find('label[for=hate_email]').addClass('error');
      $this.find('#hate_email').addClass('error');
    }
    if ($.inArray( 'send', feedback )>-1)
    {
      $this.find('span.btn_feedback').next().css('display', 'none');
      $this.find('span.btn_feedback').css('display', 'block');
      setTimeout( function(){        
        $this.find('span.btn_feedback').next().css('display', 'block');
        $this.find('span.btn_feedback').css('display', 'none');
        $this.find('input[type=text], textarea').val('').trigger('blur').trigger('keyup');        
        $('#hate_clear').attr('checked', false).next().removeClass('checkChecked');
        $('#hate_inform').attr('checked', false).next().removeClass('checkChecked');
        $('#hate_design').attr('checked', false).next().removeClass('checkChecked');
        $('#hate_innov').attr('checked', false).next().removeClass('checkChecked');
        $('#hate_userfr').attr('checked', false).next().removeClass('checkChecked');
        $('#hate_best').attr('checked', false).next().removeClass('checkChecked');
      }, 2000 );
    }
};

$.fn.loveFormFeedback = function(feedback)
{
  $this=$(this);
  
  $this.find('label, input, textarea').removeClass('error');
  
  feedback=$.parseJSON(feedback);
    if ($.inArray( 'name', feedback )>-1)
    {
      $this.find('label[for=love_name]').addClass('error');
      $this.find('#love_name').addClass('error');
    }
    if ($.inArray( 'email', feedback )>-1)
    {
      $this.find('label[for=love_email]').addClass('error');
      $this.find('#love_email').addClass('error');
    }
    if ($.inArray( 'send', feedback )>-1)
    {
      $this.find('span.btn_feedback').next().css('display', 'none');
      $this.find('span.btn_feedback').css('display', 'block');
      setTimeout( function(){        
        $this.find('span.btn_feedback').next().css('display', 'block');
        $this.find('span.btn_feedback').css('display', 'none');
        $this.find('input[type=text], textarea').val('').trigger('blur').trigger('keyup');        
        $('#love_clear').attr('checked', false).next().removeClass('checkChecked');
        $('#love_inform').attr('checked', false).next().removeClass('checkChecked');
        $('#love_design').attr('checked', false).next().removeClass('checkChecked');
        $('#love_innov').attr('checked', false).next().removeClass('checkChecked');
        $('#love_userfr').attr('checked', false).next().removeClass('checkChecked');
        $('#love_best').attr('checked', false).next().removeClass('checkChecked');
      }, 2000 );
    }
};

$.fn.mailFormFeedback = function(feedback)
{
  $this=$(this);
  
  $this.find('label, input').removeClass('error');
  $this.find('span').removeClass('obligated_star_error');
  
  feedback=$.parseJSON(feedback);
    if ($.inArray( 'name', feedback )>-1)
    {
      $this.find('label[for=form_name]').addClass('error').prev().addClass('obligated_star_error');
      $this.find('input#form_name').addClass('error');
    }
    if ($.inArray( 'email', feedback )>-1)
    {
      $this.find('label[for=form_mail]').addClass('error').prev().addClass('obligated_star_error');
      $this.find('input#form_mail').addClass('error');
    }
    if ($.inArray( 'message', feedback )>-1)
    {
      $this.find('label[for=form_message]').addClass('error').prev().addClass('obligated_star_error');
      $this.find('input#form_message').addClass('error');
    }
    if ($.inArray( 'send', feedback )>-1)
    {
      $this.find('span.btn_feedback').next().css('display', 'none');
      $this.find('span.btn_feedback').css('display', 'block');
      setTimeout( function(){
        $this.find('span.btn_feedback').next().css('display', 'block');
        $this.find('span.btn_feedback').css('display', 'none');
        $this.find('input, textarea').val('').trigger('blur');
      }, 2000 );
    }
};

function initMailTo()
{
  $('span.mailto').each( function() {
    switch( $(this).attr('rel') )
    {
      case 'info':
        var email='info'+'@'+'etc.be';
        var text='info'+'@'+'etc.be';
      break;
      case 'orders':
        var email='orders'+'@'+'etc.be';
        var text='orders'+'@'+'etc.be';
      break;
      case 'shop':
        var email='shop'+'@'+'etc.be';
        var text='shop'+'@'+'etc.be';
      break;
      case 'support':
        var email='support'+'@'+'etc.be';
        var text='support'+'@'+'etc.be';
      break;
      case 'software':
        var email='software'+'@'+'etc.be';
        var text='software'+'@'+'etc.be';
      break;
      case 'hotline':
        var email='hotline'+'@'+'etc.be';
        var text='hotline'+'@'+'etc.be';
      break;
      case 'accounting':
        var email='accounting'+'@'+'etc.be';
        var text='accounting'+'@'+'etc.be';
      break;
      case 'adc':
        var email='info'+'@'+'ad-c.be';
        var text='info'+'@'+'ad-c.be';
      break;
      case 'kassacenter':
        var email='info'+'@'+'kassacenter.be';
        var text='info'+'@'+'kassacenter.be';
      break;
      case 'binckom':
        var email='info'+'@'+'binckom.be';
        var text='info'+'@'+'binckom.be';
      break;
      case 'rubbens':
        var email='dirk'+'@'+'rubbenskassa.be';
        var text='dirk'+'@'+'rubbenskassa.be';
      break;
    }
    $(this).replaceWith('<a href="mailto:'+email+'">'+text+'</a>');
  } );
}

function initAddress()
{
//   $.address.change( function(e){
//     console.log(e);
//   } );
}

function rpRed()
{
  var container = $('#menu_image');
  
  var heights=new Array(4, 9, 14, 19, 25, 30, 36, 42, 48, 54, 60, 67, 73, 79, 86, 93, 100, 107, 114, 122, 129, 137, 145, 153, 161, 169, 177, 186, 195, 204, 213, 222, 232, 241, 251, 261, 271, 282, 293, 303, 314, 326, 338, 349, 361, 374, 386, 399, 413, 426, 440, 454, 468, 483, 495, 495, 495, 495, 495, 495, 495, 495, 495, 495, 495, 495, 495, 495, 495, 495, 495, 495, 495, 495, 495, 495, 495, 495, 495, 495);
  
  $(heights).each( function(index){
    var div = $('<div />');
    div.css( { width: 20,
               height: heights[index],
               float: 'left',
               backgroundPosition: -1*((index)*20)+"px 0px" } );
    container.append(div);
  } );

}

function rpBlack()
{
  var prop=[{"height":17,"marginTop":"-17px"},{"height":37,"marginTop":"-37px"},{"height":58,"marginTop":"-58px"},{"height":81,"marginTop":"-81px"},{"height":104,"marginTop":"-104px"},{"height":129,"marginTop":"-129px"},{"height":155,"marginTop":"-155px"},{"height":182,"marginTop":"-182px"},{"height":211,"marginTop":"-211px"},{"height":242,"marginTop":"-242px"},{"height":274,"marginTop":"-274px"},{"height":308,"marginTop":"-308px"},{"height":344,"marginTop":"-344px"},{"height":382,"marginTop":"-382px"},{"height":423,"marginTop":"-423px"},{"height":466,"marginTop":"-466px"},{"height":511,"marginTop":"-511px"},{"height":560,"marginTop":"-560px"},{"height":612,"marginTop":"-612px"},{"height":668,"marginTop":"-668px"},{"height":728,"marginTop":"-728px"},{"height":793,"marginTop":"-793px"},{"height":864,"marginTop":"-864px"},{"height":941,"marginTop":"-941px"},{"height":1027,"marginTop":"-1027px"},{"height":1100,"marginTop":"-1100px"}];
  
  var container = $('#bg_right');
  
  $(prop).each( function(index) {
    var $this=$(this);
    var div = $('<div />');
    div.css( { width: 20,
               height: prop[index].height,
               marginTop: prop[index].marginTop,
               marginLeft: ((index)*20),
//                float: 'left',
               backgroundPosition: -1*((index)*20)+"px -"+(1100-prop[index].height)+"px" } );
    
    container.append(div);
  });
}

function rpGrey()
{
  var prop=[{"height":426,"marginTop":"-426px"},{"height":405,"marginTop":"-405px"},{"height":385,"marginTop":"-385px"},{"height":366,"marginTop":"-366px"},{"height":347,"marginTop":"-347px"},{"height":329,"marginTop":"-329px"},{"height":312,"marginTop":"-312px"},{"height":295,"marginTop":"-295px"},{"height":279,"marginTop":"-279px"},{"height":263,"marginTop":"-263px"},{"height":248,"marginTop":"-248px"},{"height":233,"marginTop":"-233px"},{"height":219,"marginTop":"-219px"},{"height":206,"marginTop":"-206px"},{"height":193,"marginTop":"-193px"},{"height":180,"marginTop":"-180px"},{"height":168,"marginTop":"-168px"},{"height":156,"marginTop":"-156px"},{"height":145,"marginTop":"-145px"},{"height":135,"marginTop":"-135px"},{"height":124,"marginTop":"-124px"},{"height":114,"marginTop":"-114px"},{"height":105,"marginTop":"-105px"},{"height":96,"marginTop":"-96px"},{"height":87,"marginTop":"-87px"},{"height":79,"marginTop":"-79px"},{"height":71,"marginTop":"-71px"},{"height":63,"marginTop":"-63px"},{"height":56,"marginTop":"-56px"},{"height":49,"marginTop":"-49px"},{"height":43,"marginTop":"-43px"},{"height":37,"marginTop":"-37px"},{"height":31,"marginTop":"-31px"},{"height":26,"marginTop":"-26px"},{"height":22,"marginTop":"-22px"},{"height":17,"marginTop":"-17px"},{"height":13,"marginTop":"-13px"},{"height":10,"marginTop":"-10px"},{"height":7,"marginTop":"-7px"},{"height":4,"marginTop":"-4px"},{"height":2,"marginTop":"-2px"}];
 
  var container = $('#bg_left');
  
  $(prop).each( function(index) {
    var $this=$(this);
    var div = $('<div />');
    div.css( { width: 20,
               height: prop[index].height,
               marginTop: prop[index].marginTop,
               marginLeft: ((index)*20),
//                float: 'left',
               backgroundPosition: -1*((index)*20)+"px "+-1*(426-prop[index].height)+"px" } );
    
//  			if(!jQuery.browser.msie || (jQuery.browser.msie && parseInt($.browser.version.substr(0,1)) > 7)){
//  				$(this).css("margin-left", $(this).index() * 20 + "px");
//  			}
    
    container.append(div);
  });
}

function initSplash()
{
  if ( $('#splash').length!=0 )
  {
    if ( $('#splash').hasClass('autoloop') )
    {
      setInterval( splashNextSlide, 3000 );
    }
    splashNextSlide();
  }
  
  var campagne=$('#campagne');
  campagne.css({  height: campagne.height(),
                  width: campagne.width() });
  
  
  $('.campagne_link').click( function(e) {
//     e.preventDefault(); 
//     
//     $.ajax( { type: 'POST',
//               url: base_url+'set_campagne',
//               beforeSend: function() {
//                 $('body').css('cursor', 'wait');
//                 $('.campagne_link').css('cursor', 'wait');
//               },
//               success: function() {
//                 
//                 $('div.choose_profile').css( { display: 'block',
//                                    bottom: -1*campagne.height() } )
//                                        .animate( { bottom: 0 }, 
//                                                  { duration: 350,
//                                                    easing: 'easeOutExpo' } );
//                 $('body').css('cursor', 'default');
//                 $('.campagne_link').css('cursor', 'default');
//               } } );
//        
  } );
}

function splashNextSlide()
{
  var container = $('#images');
  var active=container.children('img.active');
  var next=active.next();
  if ( next.length==0 )
  {
    next=container.children('img:first-child');
  }
  active.fadeOut(800).removeClass('active');
  next.fadeIn(800).addClass('active');
}


function initIE7ZindexFIX()
{
  if (( $.browser.msie ) && ( $.browser.version='7.0' ))
  {
    if ( $('#splash_container').length!=0 )
    {
      var container = $('body');
      container.css('zIndex', 10000);
      container.find('div, li, a').each( function(index){
        if ( $(this).attr('id')=='campagne' )
        {
          $(this).css('zIndex', 10000-index+5);
        }
        else
        {
          $(this).css('zIndex', 10000-index);
        }
        
      } );
      $('#snow').css('zIndex', 10000);
    
//       var zindex =$('#campagne').css('zIndex');
//       console.log( zindex );
  
    }
  }
}
