// AAK Jquery file

$(document).ready(function () {


    //OnLoad checked
    $(".nav ol").hide();

    // $nav functinality
    $(".nav ul > li:nth-child(1)").addClass("nav1");
    $(".nav ul > li:nth-child(2)").addClass("nav2");
    $(".nav ul > li:nth-child(3)").addClass("nav3");
    $(".nav ul > li:nth-child(4)").addClass("nav4");
    $(".nav ul > li:nth-child(5)").addClass("nav5");
    $(".nav ul > li:nth-child(6)").addClass("nav6");



    if ($(".nav a").hasClass("current")) {

        content = $(".nav li a.current").parent().parent().parent().addClass("current-wrap").find("ol").html();
        $(".subnav").html(content);
        $(".subnav").wrapInner("<ol />");

        index = $(".nav li.current-wrap").index();
        nav_color(index);
    }




    // on Nav MouseHover
    $(".nav li").hover(function () {
        //alert("Hurray its working");

        var count = $(this).find("ol > li").size();
        var index = $(this).index();

        $(".subnav").html(""); // to empty the data on every mouse hover 

        if (count > 0) {
            //$(this).find("ol > li")
            content = $(this).find("ol").html();
            $(".subnav").html(content);
            $(".subnav").wrapInner("<ol />");


        }
        nav_color(index);

    })



    // Navigation color codes
    function nav_color(index) {
        // Create a Array for the color
        var colors = new Array();
        var colorslight = new Array();
        colors[0] = "#674f8e"; colorslight[0] = "#a698bd";
        colors[1] = "#04c1e4"; colorslight[1] = "#0091ac";
        colors[2] = "#f067a3"; colorslight[2] = "#e92878";
        colors[3] = "#ffa931"; colorslight[3] = "#fcc87e";
        colors[4] = "#00c0ee"; colorslight[4] = "#70d7ef";
        colors[5] = "#bb6498"; colorslight[5] = "#dd8cbc";

        $(".subnav").css({
            backgroundColor: colorslight[index]
        })

        $(".subnav li").addClass("navi" + index);

    }



    // jquery Slider STarts here  ***********************************************************************************
    //***************************************************************************************************************

    var total_slides = $(".slides-img li").size();
    var controlwidth = 0;
    $(".slider_tab").html(); // to Clear the data on Page Load


    $(".slides-img li").each(function (index) {

        // increment on index 
        index = index + 1;

        // variables for the sliding image heading and para
        var head = $(this).find("img").attr("alt");
        var para = $(this).find("img").attr("longdesc");
        var title = $(this).find("a").attr("title");
        $(this).prepend("<div><h2>" + head + "</h2><p>" + para + "</p></div>");


        //Slider tab Data
        $(".slider_tab").append("<li>" + title + "</li>");

        //Total Width if UL tab
        controlwidth += $(".slider_tab li:nth-child(" + index + ")").width();
        controlwidth += 2;

    })

    // Onload functionalioty
    $(".slides-img li:nth-child(1)").show().addClass("active"); ;
    $(".slider_tab li:nth-child(1)").addClass("current");
    $(".slider_tab").wrapInner("<ul>");



    //Control the width
    function controlslide() {
        //alert(controlwidth);
        if (controlwidth > 530) {
            current_index = $(".slider_tab li.current").index();

            if (current_index > 3) {
                $(".slider_tab li").animate({
                    left: "-=135px"
                })
            }


        }

    }

    function controlslideback() {
        //alert(controlwidth);
        if (controlwidth > 530) {
            current_index = $(".slider_tab li.current").index();

            if (current_index > 2) {
                $(".slider_tab li").animate({
                    left: "+=135px"
                })
            }


        }

    }


    // Onclick event
    $(".slider_tab li").click(function () {

        //to intilize the index variable
        index = $(this).index();
        index = index + 1;


        // To call the fucntion
        active(index);




    })




    //Functionn to Display Li
    function active(index) {
        //alert(index);

        $(".slides-img li").hide().removeClass("active");
        $(".slides-img li:nth-child(" + index + ")").fadeIn().addClass("active");

        // to add Class on current Tab
        $(".slider_tab li").removeClass("current");
        $(".slider_tab li:nth-child(" + index + ")").addClass("current");

    }


    // next click functionality	
    $(".next").click(function () {

        if (!($(".slider_tab li:last").hasClass("current"))) {

            $(".slider_tab li").each(function (index) {

                if ($(this).hasClass("current")) {
                    remove_auto()
                    index = index + 2;
                    active(index);
                    controlslide();
                    return (false);

                }
            })
        }
    })


    // prev click functionality	
    $(".prev").click(function () {

        if (!($(".slider_tab li:first").hasClass("current"))) {

            $(".slider_tab li").each(function (index) {

                if ($(this).hasClass("current")) {
                    remove_auto()
                    active(index);
                    controlslideback();
                    return (false);

                }
            })
        }
    })




    // autoslide functionality
    var timer = setInterval(autoslides, 5000);


    function autoslides() {

        if (!($(".slider_tab li:last").hasClass("current"))) {

            $(".slider_tab li").each(function (index) {

                if ($(this).hasClass("current")) {
                    index = index + 2;
                    active(index);
                    controlslide()
                    return (false);

                }
            })
        }
        else {

            index = 1
            active(index);
            $(".slider_tab li").animate({
                left: "0"
            })

        }




    }



    // Pause Funcitonality
    $(".pause").click(function () {


        if ($(this).hasClass("play")) {
            timer = setInterval(autoslides, 5000);
            $(this).toggleClass("play");
        }
        else {

            clearInterval(timer);
            $(".pause").toggleClass("play");
        }


    })


    function remove_auto() {


        clearInterval(timer);
        $(".pause").addClass("play");
    }





    // Gallery Inner Pages Functionality
    // Starts From here

    galleryimg = $(".gallery_img li").size();
    gallerythumb = $(".gallery-slides li").size();

    $(".gallery-slides li").click(function () {

        current = $(this).index();
        current++;
        gallery_img(current);
        // height_adjust(".gallery_img");
    })


    //Gallery onload


    current = 1;
    gallery_img(current);



    $(".galnext").click(function () {



        if (!($(".gallery-slides li:last").hasClass("current"))) {
            $(".gallery-slides li").each(function () {

                if ($(this).hasClass("current")) {

                    current = $(this).index();
                    current = current + 2;
                    gallery_img(current);
                    gal_slide_frw()
                    return false;
                }


            })

        }
    })


    $(".galprev").click(function () {



        if (!($(".gallery-slides li:first").hasClass("current"))) {
            $(".gallery-slides li").each(function () {

                if ($(this).hasClass("current")) {

                    current = $(this).index();
                    //current = current - 1;
                    gallery_img(current);
                    gal_slide_rew()

                    return false;
                }


            })

        }
    })



    function gallery_img(current) {



        $(".gallery_img li").hide();
        $(".gallery_img li:nth-child(" + current + ")").fadeIn();

        $(".gallery-slides li").removeClass("current");
        $(".gallery-slides li:nth-child(" + current + ")").addClass("current");


        /************* for Alt & Desc *************/
        /******************************************/
        $alt = $(".gallery-slides li:nth-child(" + current + ")").find("img").attr("alt");
        $longdesc = $(".gallery-slides li:nth-child(" + current + ") img").attr("longdesc");

        if ($alt != "") {

            $(".gallery_img li:nth-child(" + current + ")").find("h3").html("");
            $(".gallery_img li:nth-child(" + current + ")").prepend("<h3>" + $alt + "</h3>")
        }

        if ($longdesc != "") {

            $(".gallery_img li:nth-child(" + current + ")").find("p").html("");
            $(".gallery_img li:nth-child(" + current + ")").append("<p>" + $longdesc + "</p>");
        }

        /************* EOF for Alt & Desc *************/
        /**********************************************/


        /************* Image Link passes *************/
        /*********************************************/
        $link = $(".gallery-slides li:nth-child(" + current + ")").find("a").attr("id");
        $(".gallery_img li:nth-child(" + current + ")").find("img").attr("src", $link);





        /************* Eof Image Link passes *************/
        /*************************************************/
    }

    gal_width = 123 * gallerythumb;
    //alert(gal_width);


    function gal_slide_frw() {

        if (gal_width > 860) {
            current_index = $(".gallery-slides li.current").index();

            // height_adjust(".gallery_img");
            if (current_index > 6) {
                $(".gallery-slides li").animate({
                    left: "-=123px"
                })


            }


        }
    }


    function gal_slide_rew() {

        if (gal_width > 860) {
            current_index = $(".gallery-slides li.current").index();
            //height_adjust(".gallery_img");
            if (current_index > 5) {
                $(".gallery-slides li").animate({
                    left: "+=123px"
                })
            }


        }
    }


    function height_adjust(div_name) {


        current_height = $(div_name).height() - 200;
        mar_top = current_height / 2;
        mar_top = mar_top - 102;
        //alert(mar_top);

        $(".galprev, .galnext").height(current_height);

        $(".galprev img, .galnext img").css({ "margin-top": mar_top });


    }



    // ***  Gallery Small Inner pages functionality start from here **/ 

    // Gallery Inner Pages Functionality
    // Starts From here



    gallerythumb_s = $(".small-slider-tab li").size();

    $(".small-slider-tab li").click(function () {

        current = $(this).index();
        current++;
        gallery_img_s(current);

    })


    //Gallery onload


    current = 1;
    gallery_img_s(current);



    $(".galnext_s").click(function () {



        if (!($(".small-slider-tab li:last").hasClass("current"))) {

            $(".small-slider-tab li").each(function () {

                if ($(this).hasClass("current")) {

                    current = $(this).index();
                    current = current + 2;
                    gallery_img_s(current);
                    gal_slide_frw_s()
                    return false;
                }


            })

        }
    })


    $(".galprev_s").click(function () {



        if (!($(".small-slider-tab li:first").hasClass("current"))) {
            $(".small-slider-tab li").each(function () {

                if ($(this).hasClass("current")) {

                    current = $(this).index();
                    //current = current - 1;
                    gallery_img_s(current);
                    gal_slide_rew_s()

                    return false;
                }


            })

        }
    })



    function gallery_img_s(current) {


        //alert(current);
        $(".small-slider li").hide();
        $(".small-slider li:nth-child(" + current + ")").fadeIn()
        $(".small-slider-tab li").removeClass("current");
        $(".small-slider-tab li:nth-child(" + current + ")").addClass("current");

    }

    gal_width_s = 107 * gallerythumb_s;
    //alert(gal_width_s);


    function gal_slide_frw_s() {

        if (gal_width_s > 315) {
            current_index = $(".small-slider-tab li.current").index();

            //height_adjust(".gallery_img");
            if (current_index > 2) {
                $(".small-slider-tab li").animate({
                    left: "-=107px"
                })


            }


        }
    }


    function gal_slide_rew_s() {

        if (gal_width_s > 315) {

            current_index = $(".small-slider-tab li.current").index();
            //height_adjust(".gallery_img");
            if (current_index > 1) {

                $(".small-slider-tab li").animate({
                    left: "+=107px"
                })
            }


        }
    }



    //*** GAllery Small inner pages functionality Ends here **/


    // zoom Image Resize starts here

    //	docwidth = $(document).width();
    //alert(docwidth);
    imgwidth = $(".zoomimg").width();

    // if (imgwidth > 600) {

    $(".zoomimg").addClass("zoomin");
    //}

    $(".zoomimg").click(function () {

        $(this).toggleClass("zoomin");
        $(this).toggleClass("zoomOut");

    })


    $(document).resize(function () {
        //docwidth = $(window).width();
        //alert("chnage");

    })

    // EOF Zoom image Resize..



    // Caption Div Functionality 
    $imgcaption = $(".caption").attr("caption");
    $(".caption").append("<span>" + $imgcaption + "</span>");



})



var windowObjectReference; // global variable

function openFFPromotionPopup(ImageID) {
    windowObjectReference =
window.open("ImageDetails.aspx?id=" + ImageID,
   "DescriptiveWindowName",
   "width=700,height=500,menubar=no,location=no,resizable=no,status=yes");
}

function openFFPromotionPopupURL(url) {
    windowObjectReference =
window.open(url,
   "DescriptiveWindowName",
   "width=700,height=500,menubar=no,location=no,resizable=no,status=yes");
}

