/**
 * ------------------------------------------------------------
 * @author: Mohammed Bilal Awan, UI Lead - Atom Digital Dubai.
 * @web url: http://www.uipress.com
 * ------------------------------------------------------------
 */

 
var handleVSlider = {

    totalPages: 0,
    height: 0,
    element: "",
    clickActive: true,
    nav: "",
	seed:0,
    init: function (el, nav, height, seed) {

        this.totalPages = $(el + " li").length;
        this.height = height;
        this.element = el;
        this.nav = nav;
		this.seed = seed;
        $(el).css({ "height": (height * this.totalPages) + "px" });
        this.handleNav();
		this.handleClose();

    },

    navManager: function () {

        $(this.nav + "li a").removeClass("active");
        $(this.nav + "li a").eq(this.pageId).addClass("active");

    },

    handleNav: function(){
	
		var that = this;
		$(this.nav + " li a").bind("click", function(){
			
			if($("#banner-wrapper "+that.element).length)
				$("#banner-wrapper .overlay").fadeIn("slow");
			$(that.element).animate({marginTop: -(($(this).parent().index()+that.seed) * that.height) + "px"}, {duration:600,queue:false}, "easeOutCubic", function(){
				that.clickActive = true;
			});
			that.pageId = $(this).parent().index();
			that.navManager();
			return false;
			
		});
		
	},
	handleClose:function(){
		var that=this;
		$(this.element+" li a.close").bind("click", function(){
			$("#banner-wrapper .overlay").fadeOut("slow");
			$(that.element).animate({marginTop: "0px"}, {duration: 600,queue: false}, "easeOutCubic", function(){
				that.clickActive = true;
			});
			that.pageId = 0;
			that.navManager();
			return false;
			
		});		
	}

};function clonerVSlider() {} clonerVSlider.prototype = handleVSlider;



var handleHSlider = {

    pageId: 0,
    totalPages: 0,
    width: 0,
    btnBack: "",
    btnNext: "",
    element: "",
    clickActive: true,
    init: function (el, back, next, width) {

        this.totalPages = $(el + " li").length;
        this.width = width;
        this.btnBack = back;
        this.btnNext = next;
        this.element = el;
        this.buttonManager();

        $(el).css({ "width": (width * this.totalPages) + "px" });
        this.handlebtnNext();
        this.handlebtnBack();

    },

    buttonManager: function () {

        if (this.pageId == 0) {
            $(this.btnBack).find("img").attr("src", $(this.btnBack).find("img").attr("src").replace("_active.gif", ".gif"));
            $(this.btnBack).css({ "cursor": "default" });
        }
        else if (this.pageId == (this.totalPages - 1)) {
            $(this.btnNext).find("img").attr("src", $(this.btnNext).find("img").attr("src").replace("_active.gif", ".gif"));
            $(this.btnNext).css({ "cursor": "default" });
        }
        else {
            if ($(this.btnBack).find("img").attr("src").indexOf("_active") == -1) {
                $(this.btnBack).find("img").attr("src", $(this.btnBack).find("img").attr("src").replace(".gif", "_active.gif"));
                $(this.btnBack).css({ "cursor": "pointer" });
            }
            if ($(this.btnNext).find("img").attr("src").indexOf("_active") == -1) {
                $(this.btnNext).find("img").attr("src", $(this.btnNext).find("img").attr("src").replace(".gif", "_active.gif"));
                $(this.btnNext).css({ "cursor": "pointer" });
            }
        }


    },

    handlebtnNext: function () {

        var that = this;
        $(that.btnNext).bind("click", function () {


            if (that.clickActive == true && that.pageId < that.totalPages - 1) {
                that.clickActive = false;
                $(that.element).animate({ marginLeft: -((that.pageId + 1) * that.width) + "px" }, 600, "easeOutCubic", function () { that.clickActive = true; });
                that.pageId += 1;
                that.buttonManager();
            }

            return false;

        });

    },

    handlebtnBack: function () {

        var that = this;
        $(that.btnBack).bind("click", function () {


            if (that.clickActive == true && that.pageId > 0) {
                that.clickActive = false;
                $(that.element).animate({ marginLeft: -((that.pageId - 1) * that.width) + "px" }, 600, "easeOutCubic", function () { that.clickActive = true; });
                that.pageId -= 1;
                that.buttonManager();
            }

            return false;

        });

    }
};function clonerHSlider() {} clonerHSlider.prototype = handleHSlider;


var handleAccordion = {
    element: "",
    init: function (el) {

        var that = this;
        this.element = el;
        if(!$(this.element).parent().hasClass("fullnews"))
        $(this.element + " li").eq(0).addClass("active");

        $(this.element + " li>a").bind("click", function () {

            if (!$(this).parent().hasClass("active")) {

                $(this).parent().parent().find("div.details").slideUp("slow");
                $(this).parent().find("div").slideDown("slow", function () {

                    $(this).parent().parent().find("li.active").removeClass("active");
                    $(this).parent().addClass("active");

                });

            }
            return false;
        });

    }
};       function clonehandleAccordion() { } clonehandleAccordion.prototype = handleAccordion;


var tRotator = {

    elementIndex: 0,
    totalElements: 0,
    clickActive: true,
    rotate: function () {
        this.totalElements = JQ(".hlist ul>li").length;
        JQ(".hlist ul").css({ width: (300 * this.totalElements) });

        
       
        JQ(".hlist ul").eq(0).everyTime(8000, function () {
            if (tRotator.clickActive == true) {
                tRotator.clickActive = false;
                JQ(".hlist ul").eq(0).animate({ marginLeft: ((tRotator.elementIndex + 1) * -290) }, 1200, "easeOutCubic", function () {

                    JQ(".hlist ul>li").eq(tRotator.elementIndex).remove().appendTo(".hlist ul");
                    JQ(".hlist ul").eq(0).css({ marginLeft: 0 });
                    if (tRotator.elementIndex == $(".hlist ul>li").length - 1)
                        tRotator.elementIndex = 0;
                    tRotator.clickActive = true;

                });
            }

        });

        JQ(".scroll-nav a.right").bind("click", function () {

            if (tRotator.clickActive == true) {
                tRotator.clickActive = false;
                JQ(".hlist ul").eq(0).animate({ marginLeft: ((tRotator.elementIndex + 1) * -290) }, 1200, "easeOutCubic", function () {
                    JQ(".hlist ul>li").eq(tRotator.elementIndex).remove().appendTo(".hlist ul");
                    JQ(".hlist ul").eq(0).css({ marginLeft: 0 });
                    if (tRotator.elementIndex == JQ(".hlist ul>li").length - 1)
                        tRotator.elementIndex = 0;
                    tRotator.clickActive = true;
                });
            }
            return false;
        });

        JQ(".scroll-nav a.left").bind("click", function () {

            if (tRotator.clickActive == true) {
                tRotator.clickActive = false;
                JQ(".hlist ul>li").eq(tRotator.totalElements - 1).remove().prependTo(".hlist ul");
                JQ(".hlist ul").eq(0).css({ marginLeft: -290 });

                JQ(".hlist ul").eq(0).animate({ marginLeft: ((tRotator.elementIndex + 1) * 0) }, 1200, "easeOutCubic", function () {
                if (tRotator.elementIndex == $(".hlist ul>li").length - 1)
                tRotator.elementIndex = 0;
                tRotator.clickActive = true;
                });
            }
            return false;
        });

    }

}

