﻿var autoTransition = true;
var isEdit;

function nickelMaster(edit)
{
    isEdit = (edit == 'True');
    if (!isEdit)
    {
        //rotating banner
        featuredNews();
        
        //features (tabbed) control
        $("#tabs").tabs();
        
        //mega menu
        function megaHoverOver(){
            $(this).addClass("hover");
                $('.sub',this).css('display', 'block');					
        }
        function megaHoverOut(){ 
             $(this).removeClass("hover");
                $('.sub',this).css('display', 'none');		              
        }
        var config = {    
             sensitivity: 7, // number = sensitivity threshold (must be 1 or higher)    
             interval: 1, // number = milliseconds for onMouseOver polling interval    
             over: megaHoverOver, // function = onMouseOver callback (REQUIRED)    
             timeout: 1, // number = milliseconds delay before onMouseOut    
             out: megaHoverOut // function = onMouseOut callback (REQUIRED)    
        };
        
        $("ul.topNavLeft li").hoverIntent(config);

        //add drop shadows around images, but ignore those images within divs with class 'stories' or within divs with id 'tabs'
        //now two lines, one added to handle images that should be floating right.
        $("img").filter(function() {return (($(this).parents('.stories').length < 1) && ($(this).parents('#tabs').length < 1) && ($(this).css('float') != 'right')) ;}).wrap("<span class='overlay'><span class='innerOverlay'></span></span>");
        $("img").filter(function() {return (($(this).parents('.stories').length < 1) && ($(this).parents('#tabs').length < 1) && ($(this).css('float') == 'right')) ;}).wrap("<span class='overlay overlayRight'><span class='innerOverlay'></span></span>");
    }
    else
    {
        document.getElementById("body").setAttribute("class", "bodyEdit");
    }
}

function featuredNews()
{    
    $(".story:first").show();
	$(".story:first").prev().css({'opacity': '0.75'}).addClass("storyMenuActive").animate({'opacity': '1'});	
    $(".storyMenu").css({'opacity': '0.65'});

	currentlySelected = $(".story:first").attr('id');
	$(document).everyTime('8s', 'featuredNewsTimer', function() {
		if (autoTransition)
			showNextArticle();
	});
	
	$(".stories").mouseover(function() {
		autoTransition = false;
	});
	$(".stories").mouseleave(function() {
		$(document).oneTime(1000, function() {
			autoTransition = true;
		});
		
	});
}
function showArticle(articleId)
{
    if (!isEdit)
    {
	    //alert(articleId);
	    $(".story").hide();
	    $(".storyMenu").css({'opacity': '0.75'}).removeClass("storyMenuActive");
	    $("#"+articleId).show();
	    $("#"+articleId).prev().css({'opacity': '0.75'}).addClass("storyMenuActive").animate({'opacity': '1'});
	    currentlySelected = articleId;
	}
}
function showNextArticle()
{
	if ($("#"+currentlySelected).next().next().attr('class') == 'story')
		showArticle($("#"+currentlySelected).next().next().attr('id'));
	else
		showArticle($(".story:first").attr('id'));
}
