﻿//Preload default images.
$.preloadImages(
"/Content/images/common/character1.png",
"/Content/images/common/character2.png",
"/Content/images/common/character3.png",
"/Content/images/common/character4.png",
"/Content/images/common/character5.png",
"/Content/images/common/character6.png",
"/Content/images/common/character7.png",
"/Content/images/common/character8.png",
"/Content/images/common/character1Hov.png",
"/Content/images/common/character2Hov.png",
"/Content/images/common/character3Hov.png",
"/Content/images/common/character4Hov.png",
"/Content/images/common/character5Hov.png",
"/Content/images/common/character6Hov.png",
"/Content/images/common/character7Hov.png",
"/Content/images/common/character8Hov.png",
"/Content/images/common/home_communityHov.png",
"/Content/images/common/home_connectedHov.png",
"/Content/images/common/home_empoweredHov.png",
"/Content/images/common/home_readyHov.png",
"/Content/images/common/figureText.png",
"/Content/images/common/charater_boxTop.png",
"/Content/images/common/charater_boxMid.png",
"/Content/images/common/midBox_top.png",
"/Content/images/common/midBox_mid.png",
"/Content/images/common/midBox_bot1.png",
"/Content/images/common/midBox_bot2.png",
"/Content/images/common/midBox_bot3.png",
"/Content/images/common/midBox_bot4.png",
"/Content/images/common/historyTop_prevHov.png",
"/Content/images/common/historyTop_nextHov.png",
"/Content/images/common/historyBot_prevHov.png",
"/Content/images/common/historyBot_nextHov.png"
);




var a;
var b;

var CharacterID;

//Times the hiding of each box
var Timers = new Array();
//Times the hiding of the box contianer
var Timers2 = new Array();
//Sets a bool to determine whether each box can be shown or not
var Go = new Array();
//Sets a bool to determine if the mouse if over the current figure
var fOns = new Array();



$(document).ready(function() {


    //New Functionality for DZ Main Page Upgrade

 //   $("#State").live('change', function() {
       // var state = $(this).val();
       // var url = "Home/RegionalData/0?state=" + state;
 //       $("#loadAjx").show();
       // $.get(url, function(data) {
         //   $("#locAjx").html(data);
         //   $("#loadAjx").hide();
     //   });
   // });

    //End Upgrade




    //Loop and set default for each figure
    $(".figure").each(function() {
        var id = $(this).attr("id").substring(6);
        Go[id] = true;
        fOns[id] = false;
    });

    //Set condition of fOns on mouseover and mouseout
    $(".figure").mouseover(function() {
        var id = $(this).attr("id").substring(6);
        fOns[id] = true;
    }).mouseout(function() {
        var id = $(this).attr("id").substring(6);
        fOns[id] = false;
    });

    //Show box when hovering over figure
    $(".figure").hover(function() {
        var id = $(this).attr("id").substring(6);
        FigureUp(id);
    }, function() {
        var id = $(this).attr("id").substring(6);
        FigureDown(id);
    }
    );

    //Show box when hovering over box
    $(".figureText").hover(function() {
        var id = $(this).attr("id").substring(10);
    }, function() {
        var id = $(this).attr("id").substring(10);
    }
    );

    //Close box on clcking x
    $(".closeBox").click(function() {
        //        $('.characterBox').hide();
        return false;
    });

});


function ChangeLocation()
{
	var state = $("#State").val();
	var url = "Home/RegionalData/0?state=" + state;
	$("#loadAjx").show();
	$.get(url, function(data) {
		$("#locAjx").html(data);
		$("#loadAjx").hide();
	});
}

//Function to be called to show text
function FigureUp(id) {
    if (Go[id]) {
        clearTimeout(Timers[id]);
        clearTimeout(Timers2[id]);
        Go[id] = false;
        $("#figureText" + id).show();
        $("#figureText" + id + " .innerFigure").slideDown(500);
        $("#figure" + id + " a.fig").addClass("figure" + id + "Hov");
    }
}

//Function to hide text
function FigureDown(id) {
    Timers[id] = setTimeout("FigureUnFreeze('" + id + "')", 500);
    $("#figureText" + id + " .innerFigure").slideUp(500);
    $("#figure" + id + " a.fig").removeClass("figure" + id + "Hov");
//    FigureUnFreeze(id);
}

//Function to allow showing of text again
function FigureUnFreeze(id) {
   Go[id] = true;
    Timers2[id] = setTimeout("HideFigBox('" + id + "')", 200);
   // HideFigBox(id);

//    $("#figure" + id + " a.fig").removeClass("figure" + id + "Hov");
    //If mouse waiting on figure, show text once timeout
//    if (fOns[id]) {
//        FigureUp(id);
//    }
}

function HideFigBox(id) {
    $("#figureText" + id).hide();
}   


//Ajax to initilalize on ajax load. Call this onSuccess for every ajax link.
function AjaxCompleteInit() {
    AjaxInit();
    DZAjaxInit();
}

function DZAjaxInit() {
    $('.characterBox').show();

    $(".closeBox").click(function() {
        $('.characterBox').hide();
        return false;
    });
    
    $("#Location").change(function() {
        var state = $(this).val();
        var url = "/Chapter/Area/?state=" + state;
        $.get(url, function(data) {
            $("#chapterAreaHold").html(data);
        });
        url = "/Chapter/NewsPreview/?state=" + state;
        $.get(url, function(data) {
            $("#newsAreaHold").html(data);
        });
    });
}
   
