﻿/*  ------------------------------------------------
	GENERAL JAVASCRIPTS

	The following is executed on document ready.
	------------------------------------------------*/

$(document).ready(function() {

    /*  ------------------------------------------------
	    TABS OPEN/CLOSE

	    Shows content of clicked tab. Hides other open 
	    tabs. Action is activated by clicking tab or 
	    close link. Any open tab is hidden when user 
	    clicks outside the tabs content area.
	    ------------------------------------------------*/
        $(".tab").click(function(event) {
            event.preventDefault();
            var currentTabContent = $(this).next(".content");
            $(".content").not(currentTabContent).hide("fast");
            currentTabContent.toggle("fast");
            $(".tab").not(this).removeClass("active");
            $(this).toggleClass("active");
        });

        $(".closeTab").click(function(event) {
            event.preventDefault();
            closeTab(".tab.active");
        });
        
        // Close tabs if click outside
	    var mouseInsideTab = false;

	    $(".content").hover(function(){
		    mouseInsideTab = true;
	    }, function(){
		    mouseInsideTab = false;
	    });

	    $("html").mouseup(function(event){
		    if(! mouseInsideTab) {
			    var target = $(event.target);
			    if(!target.hasClass("active")) {
				    closeTab(".tab.active");
			    }
		    }
	    });
	    
	    
	 /*  ------------------------------------------------
		CYCLE BANNERS
		
		Banners can be shown in a carousel format. The 
		carousel plugin is CyclePlugin.
		http://jquery.malsup.com/cycle/
		http://jquery.malsup.com/cycle/options.html
		------------------------------------------------*/
		jQuery(document).ready(function() {
			jQuery(".containerCycleBanner").each( function (i) {
				$(".cycleBanner", this).cycle({
					fastOnEvent: 200,
					fx: "fade",
					timeout: 7000,
					next: $(".next", this),
					prev: $(".prev", this),
					pager: $(".navBannerPager", this),
					pause: true,
					delay: 500,
					speed: 1000,
					cssAfter: {
						zIndex: 0
					}
				});
			});
		});
	    
	    
	 /*  ------------------------------------------------
	    CAROUSEL - MAGAZINE COVERS

	    Magazine covers are shown in a carousel format. 
	    The carousel plugin is ImageFlow. Create an 
	    instance of ImageFlow and define options that 
	    override the default settings in the plugin js.
	    http://finnrudolph.de/ImageFlow/Documentation
	    ------------------------------------------------*/
		if ($("#magazineCovers").length > 0)
		{
			var instanceOne = new ImageFlow();
			instanceOne.init({ 
				ImageFlowID: 'magazineCovers',
				aspectRatio: 2.1,
				imageCursor: 'pointer',
				onClick: function() {
					window.open(this.getAttribute("data-href"), "_self")
				},
				reflections: false,
				reflectionP: 0.0,
				sliderWidth: 14,
				xStep: 130
			});
		}
});


/*  ------------------------------------------------
	TABS OPEN/CLOSE

	Functions for show and hiding tabs content.
	------------------------------------------------*/
// Open tab
function openTab(tab) {
	$(tab).next(".content").show("fast");
	$(tab).addClass("active");
}

// Close tab
function closeTab(tab) {
	$(tab).next(".content").hide("fast");
	$(tab).removeClass("active");
}
