/*

	Filename             sitewide.js
	Detail               Site functionality
	Author:              thunder::tech inc.
	License:             CLIENT is defined as the owner of online property from which this file resides or this code is referenced in.
						 ADDITIONAL PARTY is defined as anyone other than thunder::tech or CLIENT.
						 No right is granted to ADDITIONAL PARTY to sell, distribute, modify or otherwise transfer the following source code without explicit written permission by CLIENT or thunder::tech.

*/

/*  ================================
     Sitewide JavaScript
    ================================ */

thunder.client.project.pageLoaded = function()
{
	//thunder.client.project.flashReplace();
	//thunder.client.modify.rollImages();
	//thunder.client.modify.linkOptions();
	//thunder.client.modify.tabSet();
	thunder.client.modify.treeMenu(false, true);
	//thunder.client.modify.treeMenu(false, true, [thunder.client.modes.separatorTreeMenu]);
	//thunder.client.modify.treeMenu(false, true, [thunder.client.modes.imageTreeMenu]);
	thunder.client.modify.selfLabelFields();
	//thunder.client.modify.requireFields();
	//thunder.client.modify.dropSelector(true);
	//thunder.client.modify.scrollFeature(640, 3000, 500);
	//thunder.client.workarounds.alphaImages();
}

$(window).load(function(){
	//IE issues not allowing the background change in CSS
	$(".menu-dropdown a").mouseenter(function(){
		$(this).css("background", "#FFF");								  
	}).mouseleave(function(){
		$(this).css("background", "none");								  
	});
	
	if($(".left-calendar").length > 0){
		$(".left-calendar .entry:nth-child(2n)").css("background", "#FFF");
	}
});

thunder.client.project.flashReplace = function()
{
	$('.flash-billboard').flash(
		{
			swf: 'flash/billboard.swf',
			height: 200,
			width: 800,
			allowFullScreen: true,
			allowScriptAccess: 'always',
			hasVersion: 9,
			wmode: 'transparent',
			flashvars: {
				basePath: ''
			}
		}
	);
}

var intval, top, botLimit, temp;

var group = "party";
var counter = 0;
var gallery = new Array();
var curIndex = 0;
var photoArray;
var isShown = false;
var jData = null;


$(document).ready(function () {
    if ($(".topArrow").length > 0) {
        $(".topArrow").mouseenter(function () { intval = setInterval('scrollServicesUp(4)', 6); }).mouseout(function () { clearInterval(intval); });
        $(".botArrow").mouseenter(function () { intval = setInterval('scrollServicesDn(-4)', 6); }).mouseout(function () { clearInterval(intval); });

        $(".topArrow").click(function () { scrollServicesUp(60); });
        $(".botArrow").click(function () { scrollServicesDn(-60); });
        botLimit = ($(".albums-container").height() - $(".galleryList").height()) * -1;
    }
	
	if(document.location.href.indexOf("/thunder") < 0){
		if ($(".subBanner img").size() > 0) {
			var imgs = new Array();
			var x = 0;
			var randNum = Math.floor(Math.random() * $(".subBanner img").size())
			$(".subBanner img").each(function () {
				imgs[x] = $(this).attr("src");
				x += 1;
			});
			$(".subBanner").html("<img src='" + imgs[randNum] + "'>");
	
		} else {
			//$(".subBanner").html("<img src='/themes/main/images/sub-banner.jpg'>");
		}
	}
    
});

function initGallery() {
    $("body").append('<div class="galleryBackdrop"></div><div class="bigImage"><a href="javascript:void(0);" class="leftBtn"><img src="/themes/main/images/bigpic-leftbtn.png" /></a><img src="#" class="image" /><a href="javascript:void(0);" class="rightBtn"><img src="/themes/main/images/bigpic-rightbtn.png" /></a><a href="#" class="closeBtn"><img src="/themes/main/images/close-button.png" /></a></div><div class="bigImageBG"></div>');

    $.each($(".galleryCol img"), function(i) {
        $(this).click(function() { initPop(i); return false; });
        gallery[i] = $(this);
    });


    $(".leftBtn").click(function() {
        movePhoto(-1);
    });

    $(".rightBtn").click(function() {
        movePhoto(1);
    });


    $(".closeBtn").click(function() {
        $(".bigImage").hide();
        $(".galleryBackdrop").hide();
        isShown = false;
    });

    $(window).resize(function() {
        $(".bigImage").css("top", ($(window).height() - $(".bigImage .image").height()) / 2 + $(window).scrollTop() + "px");
        $(".bigImage").css("left", ($(window).width() / 2) - ($(".bigImage .image").width() / 2) + $(window).scrollLeft() + "px");
    });

    $(window).scroll(function() {
        if ($(".bigImage .image").height() >= $(window).height()) return;
        $(".bigImage").css("top", ($(window).height() - $(".bigImage .image").height()) / 2 + $(window).scrollTop() + "px");
        $(".bigImage").css("left", ($(window).width() / 2) - ($(".bigImage .image").width() / 2) + $(window).scrollLeft() + "px");
    });

}



function initPop(cIndex) {
    curIndex = cIndex; //update our tracking index

    //get the image at the given index
    var x = gallery[curIndex];
    if (isShown == false) $(".galleryBackdrop").show();

    movePhoto(0);
    isShown = true;
}

function movePhoto(increment) {    
    curIndex += increment; //update our tracking index

    var modID = Math.abs(curIndex % gallery.length);

    //get the image at the given index
    var x = gallery[modID];
    
    var img = new Image();
    img.src = x.attr("large");
    
    $(img).load(function() {       
        $(".bigImage .image").attr("src", x.attr("large"));
        $(".bigImage").show().css("top", ($(window).height() - $(".bigImage .image").height()) / 2 + $(window).scrollTop() + "px");
        $(".bigImage").css("left", ($(window).width() / 2) - ($(".bigImage .image").width() / 2) + $(window).scrollLeft() + "px");
        $(".bigImage").corner();
        $(".leftBtn, .rightBtn").css("top", ($(".bigImage .image").height() / 2) - 45 + "px");
    });
}

function scrollServicesUp(amt){
	top = parseInt($(".albums-container").css("top"));
	if((top + amt) <= 0){
		$(".albums-container").css("top", (top + amt) + "px");
	} else {
		$(".albums-container").css("top", "0px");
	}
	//$(".temp-count").html(top + "<br>" + amt + "<br>" + botLimit);
}

function scrollServicesDn(amt){
	top = parseInt($(".albums-container").css("top"));
	if((top + amt) >= botLimit){
		$(".albums-container").css("top", (top + amt) + "px");
	} else {
		$(".albums-container").css("top", botLimit + "px");
	}
	//$(".temp-count").html(top + "<br>" + amt + "<br>" + botLimit);
}

$(thunder.client.project.pageLoaded);
