﻿window.$ = $telerik.$;
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
function EndRequestHandler(sender, args) {
    if (args.get_error() == undefined) {
        initializeJQuery();
    }
}
function initializeJQuery() {
    $(document).ready(function() {
        //Scroll to top - is disabled in IE 6
        $("#toTop").scrollToTop({
            speed: "slow"
        });
        //Smooth anchor scrolling
        $.localScroll();

        //Drop shadow
        $(".dsClass").dropShadow({
            opacity: 1.5,
            blur: 2
        });
        $("#map_canvas").dropShadow({
            opacity: 0.2,
            blur: 5
        });

        //Image cycler from Cycle all js
        //$('#imgHolder1').fadeIn("slow");
        if ($('#imgHolder1')[0]) {

            $('#imgHolder1').cycle({
                speed: 3000,
                delay: 0,
                random: 1,
                timeout: 6000
            });
        }

        //Reflection bottom of page
        var contentHeight = $('#Holder').height(); //get height of content
        var siteHeight = $('#siteHolder').height(); //get height of content
        $('#transBG').css("background-position", "left " + contentHeight + "px"); //set top position of background trans              

        //Animated created by At your site
        $('#createdBy').hide(); //hide createdBy div
        $("#created").mouseover(function() {
            $("#createdBy").fadeIn("slow"); //show createdBy div on mousover
        });
        $("#created").mouseleave(function() {
            $("#createdBy").fadeOut("fast"); //hide createdBy div on mouseleave
        });

        //Home Page Language selection animation
        $('.homeLang').each(function(i) {
            $(this).stop().animate({ "opacity": 0.6 });
            $(this).mouseover(function() {
                $(this).stop().animate({ "opacity": 1 });
            });
            $(this).mouseleave(function() {
                $(this).stop().animate({ "opacity": 0.6 });
            });
        });

        //NewsTicker
        function ns_newsticker($items_to_fade, $ticker_time) {
            tickerchange = setInterval(ns_start_ticker, $ticker_time);
            var $tickeritem = $($items_to_fade);
            var tick = true;
            var i = 0;
            function ns_start_ticker() {
                $tickeritem.filter(":eq(" + i + ")").trigger('fade');
                if (i + 1 < $tickeritem.length)
                    i++;
                else
                    i = 0;
            }
            function ns_pause_ticker(currentItem) {
                //currentItem.addClass("stopClass");
                tick = false;
            }
            function ns_continue_ticker(currentItem) {
                //currentItem.removeClass("stopClass");
                tick = true;
            }
            $tickeritem.each(function(i) {
                $(this).bind("fade", function() {
                    $new_ticker_item = $tickeritem.filter(":eq(" + i + ")");
                    //alert($new_ticker_item.attr('class').split(' ').slice(-1));
                    if ($new_ticker_item.css("display") == "none" && tick) {// $new_ticker_item.attr('class') != "stopClass") {
                        $tickeritem.filter(":visible").fadeOut(400, function() {
                            $new_ticker_item.fadeIn(400);
                        });
                    }
                });
                $(this).mouseover(function() {
                    ns_pause_ticker($(this));
                    $("#newsPadding").stop();
                    //$("#newsPadding").animate({
                    //    height: 100
                    //});
                });
                $(this).mouseleave(function() {
                    ns_continue_ticker($(this));
                    //$("#newsPadding").stop();
                    //$("#newsPadding").animate({
                    //    height: 22
                    //});
                });
            });
        }
        ns_newsticker(".ticker span", 3000); // Used to create newsticker, number defines the time between transitions in milliseconds
    });
}
initializeJQuery();

//Form validation
function submitClick() {
    //return $("#<%=form1.ClientID %>").valid();
    return $(".dotnetform").valid();
}