﻿// Classname: formatSidebarWidgets
// Description: Class to format sidebar widget
formatSidebarWidgets = function () {
    this.sidebarWidgets = $(".sidebar .widget");
	this.sidebarImages = $(".sidebar .widget .reflection");

    this.init = function () {
        this.addCorners();
		this.reflectImages();
    }

    this.addCorners = function () {
        this.sidebarWidgets.append('<div class="corner topLeft" /><div class="corner topRight" /><div class="corner btmLeft" /><div class="corner btmRight" />');
    }
	
	    this.reflectImages = function () {
        this.sidebarImages.reflect({height:0.3,opacity:0.3});
    }

    this.init();
}

// Classname: addNestedScrollyStyles
// Description: Class to control and setup nested scrolly css styles
addNestedScrollyStyles = function () {
	this.scrollys = $("nav div[id*='scrolly']");
	this.activeTab = $("#scrolly1 li.on");
	
	this.init = function () {
		this.formatScrolly1();
		this.addOnCorners();
	}
	
	this.formatScrolly1 = function () {
		var ele = this;
		
		//Subnav is hidden when no series is selected. If a listitem is 'on', show the second scrolly
		//Also take into consideration that scrolly 2 should never show for the all-access page
		var isAllAccess = window.location.href.indexOf("All-Access");
		if(ele.activeTab.length > 0 && isAllAccess == -1) {
			$("#scrolly2").show();
		}
		
		if(ele.scrollys.length > 1 && isAllAccess == -1) {
			$.each(ele.scrollys, function(index) {
				if(index == 0 && ele.activeTab.length > 0) {
					$(this).find(".corner").hide(); //Hide corners
					$(this).find("li").css("padding-bottom", "5px"); //Decrease padding
					ele.recalculateHeight($(this)); //Recalculate heights
				}
			});	
		}
	}
	
	this.addOnCorners = function () {
		this.activeTab.append('<div class="corner left" />');
		this.activeTab.append('<div class="corner right" />');	
	}
	
	this.recalculateHeight = function (object) {
		//The internal scrolly needs to be shorter since it has a child scrolly below it. Remove 17px padding to connect them.
		var height = object.height();
		var heightOffset = 17;
		height = parseInt(height) - parseInt(heightOffset);
		object.height(height);
	}
	
	this.init();
}

// Classname: LBSTabs
// Description: Class to control and setup LBS's tabbed content
LBSTabs = function () {
    //Properties
    this.tabs = $("#tab_navigation li");
    this.tab_content = $("#tab_content").children();

    //Method to initialize the class
    this.init = function () {
        this.tabs.first().addClass("on");
        this.tab_content.first().addClass("on");
    }

    //Method to switch tabs
    this.switch_tab = function (id) {
        var tab_on = this.tabs.filter(".on");
        var content_on = this.tab_content.filter(".on");
        var curr_tab_content = $("#tab_content_" + id);
        curr_tab_content.children().css("display", "none");
        tab_on.removeClass().addClass("off");
        content_on.removeClass().addClass("off");
        $("#tab_" + id).removeClass().addClass("on");
        curr_tab_content.removeClass().addClass("on");
        curr_tab_content.children().fadeIn(500);
    }
    //calls the init method
    this.init();
}

// Classname: Resources
// Description: Class to control and setup Resource page styles
Resources = function () {
	
	this.addToCartBtns = $("input.addToCart");
	
	this.init = function () {
		this.wrapAddToCartBtns();	
	}
	
	this.wrapAddToCartBtns = function () {
		this.addToCartBtns.each(function(i) {
			$(this).wrap('<div style="text-align:right;clear: both;" />');
		});
	}
	
	this.init();
}
