/**
 * Created by JetBrains PhpStorm.
 * User: Beygorghor
 * Date: 09/10/11
 * Time: 10:38
 * To change this template use File | Settings | File Templates.
 */
var slide_en_cours=1;
var last_slide = 1;
var nb_of_slide=0;
var to_delete=false;
var hour_print=new Date();
var timer=7000;
var slide_interval;



jQuery.fn.fadeIn = function(speed, callback) { 
    return this.animate({opacity: 'show'}, speed, function() { 
        if (jQuery.browser.msie)  
            this.style.removeAttribute('filter');  
        if (jQuery.isFunction(callback)) 
            callback();  
    }); 
}; 
 
jQuery.fn.fadeOut = function(speed, callback) { 
    return this.animate({opacity: 'hide'}, speed, function() { 
        if (jQuery.browser.msie)  
            this.style.removeAttribute('filter');  
        if (jQuery.isFunction(callback)) 
            callback();  
    }); 
}; 

function go_to_next_slide(){
    /*var lefp_pos=parseInt($('#slider_content').css('left'));
    $('#pt_'+slide_en_cours).removeClass('on');
    to_delete=false;
    if (slide_en_cours==nb_of_slide){
        to_delete=true;
        slide_en_cours=1;
    }else{
        slide_en_cours++;
    }
    if (slide_en_cours==(nb_of_slide)){
        var to_append="";
        $('.slider_element').each(function() {
            $(this).addClass("original");
            to_append+="<li class='slider_element'>"+$(this).html()+"</li>";
        });
        $("#slider_content").append(to_append);
        $('#slider_content').css("width",((parseInt($('#slider_content').css("width")))*2)+"px");
    }
    $('#pt_'+slide_en_cours).addClass('on');

    $('#slider_image').animate({
            left: (lefp_pos-633)+"px"},
        { duration: 500,specialEasing:
        {
            width: 'linear',
            height: 'easeOutBounce'
        },
            complete: function() {
                if (to_delete){
                    $('#slider_content').css('left',"0px");
                    $('#slider_content').css('width',((parseInt($('#slider_content').css('width')))/2)+"px");
                    $('.original').remove();
                }
            }
        });*/
    
    
    var next_slide ;
    next_slide = (slide_en_cours == nb_of_slide)? 1: slide_en_cours+1;
    go_to_slide(next_slide);
    
}

function go_to_slide(num){
    /*$('#img_slide_'+last_slide).fadeOut('slow');
    $('#img_slide_'+slide_en_cours).fadeIn();
    $('#text_slide_'+last_slide).fadeOut();
    $('#text_slide_'+slide_en_cours).fadeIn();
    */
   window.clearTimeout(slide_interval);
   //slide_interval = window.setTimeout(go_to_next_slide, timer);
    last_slide = slide_en_cours;
    slide_en_cours = num;
   
   $('#slide_element_'+last_slide).fadeTo(1000,0);
   $('#slide_element_'+num).fadeTo(1000,1, function(){ slide_interval = window.setTimeout(go_to_next_slide, timer);});
   
   $('#pt_'+last_slide).removeClass('on');
   $('#pt_'+num).addClass('on');
   
     
   
}


function loop_slider(){
    if((new Date()-hour_print)>timer){
        go_to_next_slide();
        setTimeout('loop_slider()',timer);
    }
}

$(document).ready(function () {

    var ua = navigator.userAgent;
    var isiIOS = /iPad/i.test(ua) || /iPhone/i.test(ua);
    var lang = $('html').attr('lang');
    $('.slider_element').each(function() {
        nb_of_slide++;
    });

    if (nb_of_slide>1){
        $('#pt_pt_container').css('display','block');
    }
    //$('#slider_content').css("width",(nb_of_slide*633)+"px")
    $('#access > .menu').children().children().each(function() {
         if(($(this).children().attr('title')=="Home")||(!$(this).children().attr('title'))){
             $(this).children().attr('href',($(this).children().attr('href')+lang+"/"));
         }
    });
    $('.current_page_item').prepend('<img src="/wp-content/themes/Record/images/record/menu_li_footer.png"  alt="" style="width:8px;height:4px;position:absolute;bottom:8px;left:3px;">');
    $(".menu .menu-item").mouseenter(function(event) {
        $(this).prepend('<img src="/wp-content/themes/Record/images/record/menu_li_footer.png"  class ="rebord_hover" alt="" style="width:8px;height:4px;position:absolute;bottom:8px;left:3px;">');
    });
    $(".to_empty").click(function(event) {
        if (($(this).val("Login"))||($(this).val("Password"))||($(this).attr('id')=="tracking_nummer")){
            $(this).val('');
        }
    });
    $(".to_empty").blur(function(event) {
        if ($(this).val()==""){
            if (($(this).attr('id')=="tracking_nummer")){
                if (lang=="fr"){
                    $(this).val("numéro de ticket");
                }
                if (lang=="en"){
                    $(this).val("ticket nummer");
                }
                if (lang=="nl"){
                    $(this).val("ticketnummer");
                }
            }
            if (($(this).attr('id')=="login")){
                    $(this).val("login");
            }
            if (($(this).attr('id')=="password")){
                    $(this).val("password");
            }
        }
    });
    $(".menu .menu-item").mouseleave(function(event) {
        $(".rebord_hover").remove();
    });
    var is_home = false;
    if($("body").hasClass("home")){
        is_home = true;
    }

    if (isiIOS){
        $('head').append(' <link rel="stylesheet" type="text/css" href="wp-content/themes/Record/ipad.css">');
        $('#primary').css('width',"640px");
        $('#secondary').css('width',"270px");
        $('#secondary').css('margin',"0");
        $('#secondary').css('padding',"0");
        $('#secondary').css('float',"left");
        $('#content').css('width',"634px");
        $('#content').css('margin-left',"0");
        $('#primary').css('float',"left");
        $('#main').css('width',"920px");
        $('.wtf').css('background-position',"0 1px");
    }
    if (is_home){
       // slide_interval = window.setInterval(go_to_next_slide, timer);

        if (nb_of_slide>1){
            slide_interval = window.setTimeout(go_to_next_slide, timer);
        }
    }
    $('#primary').delegate(".slider_element","click",function(e) {
      if (nb_of_slide>1){
        hour_print=new Date();
        setTimeout('loop_slider()',timer);
      }
    });
});

