// AAK Jquery file
$(document).ready(function () {

    //******************************************//
    //******************************************//	
    // Rounded corners
    $(function () {


        settings10 = {
            tl: { radius: 10 },
            tr: { radius: 10 },
            bl: { radius: 10 },
            br: { radius: 10 },
            autoPad: true,
            validTags: ["div"]
        }

        settings20 = {
            tl: { radius: 20 },
            tr: { radius: 20 },
            bl: { radius: 20 },
            br: { radius: 20 },
            autoPad: true,
            validTags: ["div"]
        }



        //  $('.corner10').corner(settings10);
        $('.corner20').corner(settings20);

        // $('.myBox2').corner();
        // custom Corners
        $("div").find(".content-left").find(".content-area").append("<div class='conrners'><span class='left-top'></span><span class='right-top'></span><span class='left-bottom'></span><span class='right-bottom'></span></div>");


    });
    $(".shadow").textShadow();
    // EOF rounded Corners
    //******************************************//
    //******************************************//		



    // toggle functionality
    //******************************************//
    //******************************************//	
    $(".toggle").prev("div").hide();
    $(".toggle").click(function () {

        $(this).prev("div").slideToggle().toggleClass("open");

        if ($(this).prev("div").hasClass("open")) {

            //alert("works");
            $(this).html("Collapse");
        } else {

            $(this).html("Read more");
        }


    })


    // Eof toggle functionality
    //******************************************//
    //******************************************//	



    // Slider Functionality
    //******************************************//
    //******************************************//	

    // Onload Slider
    $(".sl-imagediv > ul li").hide();

    // Execute Functions
    currentpos();

    // Tab click
    $(".slider .leftnav li").click(function () {

        $href = $(this).find("a").attr("href");


        window.location = $href;

    })


    // Tab hover
    $(".slider .leftnav li").hover(function () {
        stopslider();
        $(".slider .leftnav li").removeClass("current");
        $(this).addClass("current");

        // Functions Exec
        currentpos();

    })

    // Tab Auto Slider

    // autoslide functionality
    var timer = setInterval(autoslide, 3000);




    //Next Click
    $(".sl-next").click(function () {

        stopslider();
        slnextfunc();
        desc();
    })

    //Prev Click
    $(".sl-prev").click(function () {

        stopslider();
        slprevfunc();
        desc();
    })

    // click On Navigations Buttons 
    $(".sl-num li").live('click', function () {


        stopslider();
        $index = $(this).index();
        $index++;

        $leftindex = $(".leftnav li.current").index();
        $leftindex++;

        $(".sl-nav li").removeClass("active");
        $(".sl-nav li:nth-child(" + $index + ")").addClass("active");

        $(".sl-imagediv li:nth-child(" + $leftindex + ") img").removeClass("active").hide();
        $(".sl-imagediv li:nth-child(" + $leftindex + ") img:nth-child(" + $index + ")").addClass("active").show();
        desc();

    })






    // All the Functions

    // for the AutoSlide
    function autoslide() {

        //alert("test");
        //Intializing the value

        $index = $(".slider .leftnav li.current").index();
        $index++;
        if ($index < 6) {
            //alert("index"+$index);
            $current = $index + 1;
            //alert("current"+$current);
            if ($current < 6) {
                $(".sl-imagediv > ul li").hide();
                $(".sl-imagediv > ul > li:nth-child(" + $current + ")").show();

                $(".slider .leftnav li:nth-child(" + $index + ")").removeClass("current");
                $index++;
                //alert($index);
                $(".slider .leftnav li:nth-child(" + $index + ")").addClass("current");


                $(".sl-imagediv li:nth-child(" + $index + ") img").removeClass("active").hide();
                $(".sl-imagediv li:nth-child(" + $index + ") img:first").addClass("active").show();

                desc();
                nav();
            } else {
                $(".slider .leftnav li:nth-child(" + $index + ")").removeClass("current");
                $index++;
                //alert($index);
                $(".slider .leftnav li:nth-child(" + $index + ")").addClass("current");
            }

        }


    }

    function stopslider() {

        clearInterval(timer);
        //alert("test");



    }


    function currentpos() {

        //Intializing the value
        $index = $(".slider .leftnav li.current").index();
        $index++;
        //alert($index);

        $(".sl-imagediv > ul li").hide();
        $(".sl-imagediv > ul > li:nth-child(" + $index + ")").show();


        desc();
        nav();
    }

    // Title and Desc of image
    function desc() {
        //Intializing the value
        $index = $(".slider .leftnav li.current").index();
        $index++;
        //alert($index);
        // Add Data in var
        $title = $(".sl-imagediv > ul > li:nth-child(" + $index + ") img.active").attr("alt");
        $desc = $(".sl-imagediv > ul > li:nth-child(" + $index + ") img.active").attr("longdesc");

        //alert($title);
        $(".sl-desc .data h3").html($title);
        $(".sl-desc .data p").html($desc);
    }


    function nav() {

        //Intializing the value
        $index = $(".slider .leftnav li.current").index();
        $index++;

        $(".sl-nav li").removeClass("active");
        $(".sl-nav li:nth-child(1)").addClass("active");

        $size = $(".sl-imagediv > ul > li:nth-child(" + $index + ") img").size();
        //alert($size);
        if ($size == 1) {

            $(".sl-nav").hide();
        }

        if ($size == 2) {

            $(".sl-nav").show();
            $(".sl-num").html("");

            for (i = 1; i <= $size; i++) {
                $(".sl-num").append("<li>" + i + "</li>");

            }
            $width = $size * 27 + 79;
            //alert($width);
            $(".sl-nav").css({

                width: $width
            })
        }

        if ($size > 2) {


            $(".sl-nav").show();
            $(".sl-num").html("");

            for (i = 1; i <= $size; i++) {
                $(".sl-num").append("<li>" + i + "</li>");

            }
            $(".sl-nav").css({ 'width': '160px' })
            $width = $size * 27;
            $(".sl-num").css({

                width: $width
            })
        }
        $(".sl-num li:first").addClass("active");
        $(".sl-imagediv > ul > li:nth-child(" + $index + ") img:first").addClass("active");
    }

    function slnextfunc() {
        //Intializing the value
        $index = $(".slider .leftnav li.current").index();
        $index++;

        $imgsize = $(".sl-imagediv > ul > li:nth-child(" + $index + ") img").size();
        $imgindex = $(".sl-imagediv > ul > li:nth-child(" + $index + ") img.active").index();
        $imgindex++; $imgindex++;

        //alert($imgsize +" Img index:"+ $imgindex);

        if ($imgsize >= $imgindex) {

            $(".sl-imagediv > ul > li:nth-child(" + $index + ") img").removeClass("active").hide();
            $(".sl-imagediv > ul > li:nth-child(" + $index + ") img:nth-child(" + $imgindex + ")").addClass("active").show();

            $(".sl-nav li").removeClass("active")
            $(".sl-nav li:nth-child(" + $imgindex + ")").addClass("active")

            if ($imgindex > 3) {
                //	alert("in");
                $(".sl-nav li").animate({

                    left: '-=27px'
                })

            }

        }

    }


    function slprevfunc() {
        //Intializing the value
        $index = $(".slider .leftnav li.current").index();
        $index++;

        $imgsize = $(".sl-imagediv > ul > li:nth-child(" + $index + ") img").size();
        $imgindex = $(".sl-imagediv > ul > li:nth-child(" + $index + ") img.active").index();
        //$imgindex--;

        //alert($imgsize +" Img index:"+ $imgindex);

        if ($imgindex > 0) {

            $(".sl-imagediv > ul > li:nth-child(" + $index + ") img").removeClass("active").hide();
            $(".sl-imagediv > ul > li:nth-child(" + $index + ") img:nth-child(" + $imgindex + ")").addClass("active").show();

            $(".sl-nav li").removeClass("active")
            $(".sl-nav li:nth-child(" + $imgindex + ")").addClass("active")


            if ($imgindex >= 3) {
                //alert("in");
                $(".sl-nav li").animate({

                    left: '+=27px'
                })

            }

        }

    }
    // Eof Slider Functionality
    //******************************************//
    //******************************************//	



    //* Gallery Zoom Button
    //*******************************************//
    //*******************************************//

    $(".gallery li").append("<span class='zoom'></span>")

    // Eof Gallery Zoom Button
    //******************************************//
    //******************************************//




    //* Sidebar Gallery 
    //*******************************************//
    //*******************************************//

    $(".sb-small-img li").click(function () {

        $title = $(this).find("a").attr("title");
        //alert($title);
        $(".sb-big-img img").attr("src", $title)


    })

    //* EOF Sidebar Gallery 
    //*******************************************//
    //*******************************************//




    // Loading Effect

    $(".slider > div").hide('fast', loader);

    function loader() {
        $(".slider").prepend("<span class='loader'><img src='assets/images/icons/loading2.gif' alt=''></span>")
    }

    var count = 1;
    var timers = setInterval(sliderdiv, 500);

    function sliderdiv() {

        if (count == 1) {

            $(".loader").hide();
            $(".slider > div").fadeIn('slow');
            count = 2;
            //alert(count);
        }
    }


    // Hide double TB_title thickbox div
    $("#TB_window").hide().addClass("notactive");
    

})


