var LastTabOpen = "shopNewst"
var FirstCheck = true;

var headline_count;
var headline_interval;
var current_headline = 0;
var old_headline = 0;

$(document).ready(function () {

    $("div.snifim div.msgBox a").fancybox();

    $('ul.menu li:last-child').css('background-image', 'none');

    $('div.shopProd div.shopProdItem:first').css('margin-left', '7px');

    $('h3.kursSmallHeader + p').css('padding-bottom', '5px');
    $('div.snifim div.msgBox p').css('padding-bottom', '3px');
    $('div.snifim div.msgBox p:last').css('padding-bottom', '15px');
    $('div.snifim div.msgBox:last').css('border-bottom', '0');

    //index shop tabs
    $('div.shopProd').hide();
    $('div.shopProd:first').show();
    $('div.eveShop ul li:first').addClass('shopActive');

    $('div.eveShop ul li').click(function () { return false; });

    $('div.eveShop ul li').click(function () {
        $('div.eveShop ul li').removeClass('shopActive');

        if (LastTabOpen != this.className) {

            $('#' + LastTabOpen).hide();
            $('#' + this.className).show();
            LastTabOpen = this.className;
        }
        $('div.eveShop ul li.' + this.className).addClass('shopActive');
    });

    //menu hover
    $('ul.menu li').hover(
    function () {
        $(this).addClass('menuHover').children('ul').show();
    },
    function () {
        $(this).removeClass('menuHover').children('ul').hide();
    });

    //sidebar hover
    $('div.sideBar ul li a').hover(
    function () {
        $(this).addClass('sideHover');
    },
    function () {
        $(this).removeClass('sideHover');
    });

    //IndexPage More details
    $('.moreIndexDet').click(
    function () {
        $(this).hide();
        $(this).next('div').slideDown("slow");
    });


    //index scrolling news - NEW
    headline_count = $("div.newsArticle").size();
    $("div.newsArticle:eq(" + current_headline + ")").css('top', '0px');

    headline_interval = setInterval(headline_rotate, 4500);
    $('div.newsInner').hover(function () {
        clearInterval(headline_interval);
    }, function () {
        headline_interval = setInterval(headline_rotate, 4500);
        headline_rotate();
    });
    function headline_rotate() {
        current_headline = (old_headline + 1) % headline_count;
        $("div.newsArticle:eq(" + old_headline + ")")
    .animate({ top: -120 }, "slow", function () {
        $(this).css('top', '125px');
    });
        $("div.newsArticle:eq(" + current_headline + ")")
    .animate({ top: 0 }, "slow");
        old_headline = current_headline;
    }


    //video page

   


    //sidebar form validation
    $(".sideBut").click(function () {
        return checkForm();
    });

    function checkForm() {

        FirstCheck = false;
        check = true;

        $("input#ctl00_tbCity , input#tbCity").parent('div').prev('span').removeClass();
        if ($("input#ctl00_tbCity , input#tbCity").val() == "") {
            $("input#ctl00_tbCity , input#tbCity").parent('div').prev('span').addClass('fieldhover');
            $("input#ctl00_tbCity , input#tbCity").focus();
            check = false;
        }
        $("input#ctl00_tbEmail , input#tbEmail").parent('div').prev('span').removeClass();
        var email = $("input#ctl00_tbEmail , input#tbEmail").val();
        if (email == "" || !(emailChek(email))) {
            $("input#ctl00_tbEmail , input#tbEmail").parent('div').prev('span').addClass('fieldhover');
            $("input#ctl00_tbEmail , input#tbEmail").focus();
            check = false;
        }
        $("input#ctl00_tbPhone , input#tbPhone").parent('div').prev('span').removeClass();
        var phone = $("input#ctl00_tbPhone , input#tbPhone").val();
        if (phone.length < 8 || !(IsNumeric(phone))) {
            $("input#ctl00_tbPhone , input#tbPhone").parent('div').prev('span').addClass('fieldhover');
            $("input#ctl00_tbPhone , input#tbPhone").focus();
            check = false;
        }
        $("input#ctl00_tbName , input#tbName").parent('div').prev('span').removeClass();
        if ($("input#ctl00_tbName , input#tbName").val() == "") {
            $("input#ctl00_tbName , input#tbName").parent('div').prev('span').addClass('fieldhover');
            $("input#ctl00_tbName , input#tbName").focus();
            check = false;
        }
        return check;
    }


    //contact form validation
    $(".but").click(function () {
        return checkForm2();
    });

    function checkForm2() {
        FirstCheck2 = false;
        check = true;

        $("input#ctl00_ContentPlaceHolder1_tbEmail , input#tbEmail").prev('span').removeClass();
        var email = $("input#ctl00_ContentPlaceHolder1_tbEmail , input#tbEmail").val();
        if (email == "" || !(emailChek(email))) {
            $("input#ctl00_ContentPlaceHolder1_tbEmail , input#tbEmail").prev('span').addClass('fieldhover');
            $("input#ctl00_ContentPlaceHolder1_tbEmail , input#tbEmail").focus();
            check = false;
        }
        $("input#ctl00_ContentPlaceHolder1_tbPhone , input#tbPhone").prev('span').removeClass();
        var phoneCon = $("input#ctl00_ContentPlaceHolder1_tbPhone , input#tbPhone").val();
        if (phoneCon.length < 8 || !(IsNumeric(phoneCon))) {
            $("input#ctl00_ContentPlaceHolder1_tbPhone , input#tbPhone").prev('span').addClass('fieldhover');
            $("input#ctl00_ContentPlaceHolder1_tbPhone , input#tbPhone").focus();
            check = false;
        }
        $("input#ctl00_ContentPlaceHolder1_tbLastName , input#tbLastName").prev('span').removeClass();
        if ($("input#ctl00_ContentPlaceHolder1_tbLastName , input#tbLastName").val() == "") {
            $("input#ctl00_ContentPlaceHolder1_tbLastName , input#tbLastName").prev('span').addClass('fieldhover');
            $("input#ctl00_ContentPlaceHolder1_tbLastName , input#tbLastName").focus();
            check = false;
        }
        $("input#ctl00_ContentPlaceHolder1_tbName , input#tbName").prev('span').removeClass();
        if ($("input#ctl00_ContentPlaceHolder1_tbName , input#tbName").val() == "") {
            $("input#ctl00_ContentPlaceHolder1_tbName , input#tbName").prev('span').addClass('fieldhover');
            $("input#ctl00_ContentPlaceHolder1_tbName , input#tbName").focus();
            check = false;
        }
        return check;
    }




    function emailChek(str) {

        var at = "@"
        var dot = "."
        var lat = str.indexOf(at)
        var lstr = str.length
        var ldot = str.indexOf(dot)
        if (str.indexOf(at) == -1) {

            return false
        }

        if (str.indexOf(at) == -1 || str.indexOf(at) == 0 || str.indexOf(at) == lstr) {

            return false
        }

        if (str.indexOf(dot) == -1 || str.indexOf(dot) == 0 || str.indexOf(dot) == lstr) {

            return false
        }

        if (str.indexOf(at, (lat + 1)) != -1) {

            return false
        }

        if (str.substring(lat - 1, lat) == dot || str.substring(lat + 1, lat + 2) == dot) {

            return false
        }

        if (str.indexOf(dot, (lat + 2)) == -1) {

            return false
        }

        if (str.indexOf(" ") != -1) {

            return false
        }

        return true
    }

    function IsNumeric(inputVal) {
        if (isNaN(parseFloat(inputVal))) {
            return false;
        }
        else {
            return true;
        }
    }





}); 

