﻿
/// <reference path="jquery-1.4.1.min.js" />
/// <reference path="jquery-1.4.1-vsdoc.js" />


String.prototype.trim = function () { return this.replace(/^\s+|\s+$/g, ''); }

var J = jQuery.noConflict();

var bannerIndex = 0;
var totalChildren = 0;
var totalImages = 0;
var interval;

function setNavStyle() {
    J(".banner_paging a").removeClass("btn_banner_paging_active").addClass("btn_banner_paging");
    J(J(".banner_paging a")[bannerIndex]).removeClass("btn_banner_paging").addClass("btn_banner_paging_active");
}

function setNthItem(index, animateTime) {
    
    J(J(".banner_holder").children()[bannerIndex]).animate({ opacity: 0.0 }, animateTime);
    bannerIndex = index;
    J(J(".banner_holder").children()[bannerIndex]).animate({ opacity: 1.0 }, animateTime);
    setNavStyle();
}

function rotateBanner() {
    setNthItem((bannerIndex + 1) % totalImages, 2000);   
}

function initRotationWithChildIndex(index, animateTime) {
    if (index >= totalImages) return;
    setNthItem(index, animateTime);
    clearInterval(interval);
    interval = setInterval('rotateBanner()', 5000);
}

function initBannerRotaion() {

    totalChildren = J(".banner_holder").children().length;
    totalImages = totalChildren - 1; /// last child is for paging

    /// hide all banner images
    for (var i = 0; i < totalImages; i++) {
        J(J(".banner_holder").children()[i]).animate({ opacity: 0.0 }, 0);
    }
    /// inactive all banner buttons
    J(".banner_paging a").each(function (index) {
        J(this).click(function () {
            initRotationWithChildIndex(index, 500);
        })
    })

    bannerIndex = totalImages - 1;
    /// start rotation with 0th image
    initRotationWithChildIndex(0, 0);
}

J(document).ready(function () {
    J(".content_left_title a").each(function (index) {
        J(this).click(function () {

            J(".content_left_details.nodisplay").removeClass("nodisplay");
            J(".content_left_details").addClass("nodisplay");
            J(".content_left_in_in :nth-child(" + (index + 2).toString() + ")").removeClass("nodisplay");

            J(".content_left_title a").each(function () {
                var str = J(this).attr("class").toString();
                var pos = str.indexOf("_selected");
                if (pos > -1)
                    J(this).attr("class", str.substring(0, pos));
            });

            var str = J(this).attr("class").toString();
            J(this).attr("class", str + "_selected");
        });
    });

    initBannerRotaion();
});
