$(document).ready(function() {

// Wiat for DOM load in 110%
delay();

//Change toogle language box
    $(".choiceLangContent").hide();
    $("#openCloseLang").hover(function() {
        $(".sharpLangBox").remove();
        $(".sharpLangBox1").remove();
        $(".sharpLangBox2").remove();        
        var setLangContent = 20;
        var setLangContentWidth = 40;
        //Get width
        var choiceLangContentWidth = $(".choiceLangContent").innerWidth();
        // Var to check parity
        var checkLangContent = choiceLangContentWidth%2;
        // Check parity
        if ( checkLangContent == 0) { // parity checkVisit of liVisitWidth
            setLangContent = choiceLangContentWidth/2;
        } else {
            choiceLangContentWidth = choiceLangContentWidth+1;
            setLangContent = choiceLangContentWidth/2;
        }
        setLangContentWidth = setLangContent + "px solid transparent";
        // Adding div and span
        $(".choiceLangContent").append('<div class="clear sharpLangBox1"></div><div class="sharpLangBox"></div><span class="sharpLangBox2"></span>');
        // Adjust border style to div after li element
        $(".choiceLangContent div").filter(':last').css({borderLeft: setLangContentWidth});
        $(".choiceLangContent div").filter(':last').css({borderRight: setLangContentWidth});
        $(".choiceLangContent").slideToggle("fast");
         // Show block's
        $(".choiceLangContent div").filter(':last').css({display: 'block'});
        return false;
    }, function(){
        $(".choiceLangContent").slideUp("fast");        
    });
    
  // Text underline for paragraph in link 
    $('#lang_sel_list a').hover(function(){
        $(this).addClass('overLang');
        $('#lang_sel_list a.overLang p').filter(':first').css({textDecoration: 'underline'});
    }, function(){
        $(this).removeClass('overLang');
        $('#lang_sel_list p').css({textDecoration: 'none'});
    });
    

//Show extra content from the top of the site
    $(".openCloseButton").click( function() {
        if ($("#openCloseIdentifier").is(":hidden")) {
            $("#hiddenContentBox").animate({
                marginTop: "-314px"
                }, 500 );
            $("#openCloseIdentifier").show();
        } else {
            $("#hiddenContentBox").animate({
                marginTop: "0px"
                }, 500 );
            $("#openCloseIdentifier").hide();
        }
    });

// Buttons hover

    $(".narrow-button a.bebas").hover(
        function() {
            $(this).addClass('over');
            $(this).next().addClass('over');
        },
        function(){
            $(this).removeClass('over');
            $(this).next().removeClass('over');
        }
    );

    $(".narrow-button .red a.bebas").hover(
        function() {
            $(this).addClass('over');
            $(this).next().addClass('over');
        },
        function(){
            $(this).removeClass('over');
            $(this).next().removeClass('over');
        }
    );

    $("a.bebasoverRedSubmit").hover(
        function() {
            $(this).addClass('over');
            $(this).prev().addClass('over');
            $(this).next().addClass('over');
        },
        function(){
            $(this).removeClass('over');
            $(this).prev().removeClass('over');
            $(this).next().removeClass('over');
        }
    );

    $("#openCloseWrap").hover(
        function() {
            $(this).addClass('over');
            $('.openCloseWrapSharp').addClass('over');
        },
        function(){
            $(this).removeClass('over');
            $('.openCloseWrapSharp').removeClass('over');
        }
    );


    return false;

});  // end of $(document).ready(function() {


// Sets down triangle after 300ms
function delay(){
    var t=setTimeout("domReady()", 300);
}

function domReady(){
 // Var to set border width
    var setVisit = 10;
    var setOpenCloseButton = 10;
    var top = 13;

 //Get width of active li element.
    var liVisitWidth = $(".current-menu-item").innerWidth();
 //Get width of OpenClose Button
    var OpenCloseButtonWidth = $(".openCloseButton").innerWidth();
 // Var to check parity
    var checkVisit = liVisitWidth%2;
    var checkOpenCloseButtonWidth = OpenCloseButtonWidth%2;
 // Check parity of li visited element
    if ( checkVisit == 0) { // parity checkVisit of liVisitWidth
        setVisit = liVisitWidth/2;
    } else {
        liVisitWidth = liVisitWidth+1;
        setVisit = liVisitWidth/2;
    }
 // Check parity of OpenCloseButton
    if ( checkOpenCloseButtonWidth == 0) { // parity checkVisit of liVisitWidth
        setOpenCloseButton = OpenCloseButtonWidth/2;
    } else {
        liVisitWidth = OpenCloseButtonWidth+1;
        setOpenCloseButton = OpenCloseButtonWidth/2;
    }
  // Define border style
    setVisitWidth = setVisit + "px solid transparent";
    setOpenCloseButtonWidth = setOpenCloseButton + "px solid transparent";
  // Adding div and span
    $(".current-menu-item").append('<div class="sharp"></div><span></span>');    
    
  // Adjust border style to div after li element
    $(".current-menu-item div:first").css({borderLeft: setVisitWidth});
    $(".current-menu-item div:first").css({borderRight: setVisitWidth});
  // Adjust border style to div after OpenCloseButton
    $(".openCloseButton").next().css({borderLeft: setOpenCloseButtonWidth});
    $(".openCloseButton").next().css({borderRight: setOpenCloseButtonWidth});
  // Show block's
    $(".current-menu-item div:first").css({display: 'block'});
    $(".openCloseButton").next().css({display: 'block'});

}

function sendMsg () {
    $('form').submit();
}

function showsomething() {
}

// Load TransportMode content after click

    function transportModeCartStyleChange(classLi) {
        $(".transportModeCart li.openCart div:first").css({backgroundPositionX: "-286px"});
        $(".transportModeCart li.openCart").css({background: "#a99a8b"});
        $(".transportModeCart li").removeClass('openCart'); //Remove all active class
        $(".transportModeCart li."+classLi+"Cart").addClass('openCart'); //Add openCart class
        $(".transportModeCart li.openCart").css({background: "transparent url('/z javastyle/img/body-bg.png') repeat"});
        $(".transportModeCart li.openCart div:first").css({backgroundPositionX: "-20px"});
        $(".trasnportModeDesc").removeClass('openCartDescBlock'); //Remove all active class
        $("#by"+classLi).addClass('openCartDescBlock'); //Add openCart class
    };

// Slider

function slider(showTrigger){
    //Show the paging and activate its first link
    if ( showTrigger == 'hide') {
        $(".paging").hide();
    } else {
        $(".paging").show();
    }
    //$(".paging").show();
    $(".paging a:first").addClass("active");
    $(".sliderTextUp h2:first, .sliderTextDown p:first").addClass("sliderTextActive");
    $(".sliderTextUp h2:first, .sliderTextDown p:first").fadeIn(500);

    //Get size of the image, how many images there are, then determin the size of the image reel.
    var imageWidth = $(".window").width();
    var imageSum = $(".image_reel img").size();
    var imageReelWidth = imageWidth * imageSum;

    //Adjust the image reel to its new size
    $(".image_reel").css({'width' : imageReelWidth});

    //Paging  and Slider Function
    rotate = function(){
        if ( $active.attr("rel") != null) {
        var triggerID = $active.attr("rel") - 1; //Get number of times to slide
        var image_reelPosition = triggerID * imageWidth; //Determines the distance the image reel needs to slide

        // Hide text of h2 and p
        $(".sliderTextUp h2").hide();
        $(".sliderTextDown p").hide();

        $(".paging a").removeClass('active'); //Remove all active class
        $(".sliderTextUp h2").removeClass('sliderTextActive'); //Remove all active class from slider h2
        $(".sliderTextDown p").removeClass('sliderTextActive'); //Remove all active class from slider p

        $texth2Active = $('.sliderTextUp h2:eq('+triggerID+')'); //Move to the next slider h2
        $textpActive = $('.sliderTextDown p:eq('+triggerID+')'); //Move to the next slider p

        $active.addClass('active'); //Add active class (the $active is declared in the rotateSwitch function)
        $texth2Active.addClass('sliderTextActive'); //Add active class (the $active is declared in the rotateSwitch function)
        $textpActive.addClass('sliderTextActive'); //Add active class (the $active is declared in the rotateSwitch function)

        //Slider Animation
        $(".image_reel").animate({
            left: -image_reelPosition
        }, 500 );

        // Fade in the next text of h2 and p
        $(".sliderTextUp h2.sliderTextActive").fadeIn(500);
        $(".sliderTextDown p.sliderTextActive").fadeIn(500);
        }
    };

    //Rotation  and Timing Event
    rotateSwitch = function(){
        play = setInterval(function(){ //Set timer - this will repeat itself every 9 seconds
            $active = $('.paging a.active').next(); //Move to the next paging
            $texth2Active = $('.sliderTextUp h2.sliderTextActive').next(); //Move to the next slider h2
            $textpActive = $('.sliderTextDown p.sliderTextActive').next(); //Move to the next slider p
            if ( $active.length === 0) { //If paging reaches the end...
                $active = $('.paging a:first'); //go back to first
                $texth2Active = $(".sliderTextUp h2:first"); //go back to first h2
                $textpActive = $(".sliderTextDown p:first"); //go back to first p
            }
            rotate(); //Trigger the paging and slider function
        }, 10000); //Timer speed in milliseconds (9 seconds)
    };

    rotateSwitch(); //Run function on launch

    //On Hover
    $("#slider-text").hover(function() {
        clearInterval(play); //Stop the rotation
    }, function() {
        rotateSwitch(); //Resume rotation timer
    });

    //On Click
    $(".paging a").click(function() {
        $active = $(this); //Activate the clicked paging
      //Reset Timer
        clearInterval(play); //Stop the rotation
        rotate(); //Trigger rotation immediately
        return false; //Prevent browser jump to link anchor
    });

};
// ----------------------------------------------------
