﻿var intervalID;
var currentId = 0;
var screenHeight = screen.height;
var picLen = 4;
$(function () {
    //    var so = new SWFObject("flash/main.swf", "main", "990", "445", "9.0.0", "#ffffff");
    //    so.addParam("scale", "noscale");
    //    so.addParam("wmode", "opaque");
    //    so.addParam("wmode", "transparent");
    //    so.write("homeSwfDiv");
    setAutoSwitch();
    init();
});

function init() {
    var picHeight;
    if (screenHeight <= 800) {
        picHeight = 445;
        $("#Map0").find("area").eq(0).attr("coords", "808,133,965,298");
        $("#Map0").find("area").eq(1).attr("coords", "21,273,293,291");
        $("#Map1").find("area").eq(0).attr("coords", "808,133,965,298");
        $("#Map1").find("area").eq(1).attr("coords", "22,255,214,273");
        $("#Map2").find("area").eq(0).attr("coords", "22,255,146,273");
        $("#Map3").find("area").eq(0).attr("coords", "808,133,965,298");
        $("#Map3").find("area").eq(1).attr("coords", "21,276,279,293");
    }
    else if (screenHeight > 800 && screenHeight < 1024) {
        picHeight = 577;
        $("#Map0").find("area").eq(0).attr("coords", "808,250,966,414");
        $("#Map1").find("area").eq(0).attr("coords", "808,250,966,414");
        $("#Map3").find("area").eq(0).attr("coords", "808,250,966,414");
    }
    else if (screenHeight >= 1024) {
        picHeight = 630;
        $("#Map0").find("area").eq(0).attr("coords", "811,312,966,475");
        $("#Map1").find("area").eq(0).attr("coords", "811,312,966,475");
        $("#Map3").find("area").eq(0).attr("coords", "811,312,966,475");
        $('.defaultcallout').addClass('defaultcallout_hi_res');
    }
    for (var i = 0; i < picLen; i++) {
        $("#noflash_img_" + i).attr("height", picHeight).attr("src", "img/no_flash_" + picHeight + "_" + i + ".jpg");
    }
}

function setAutoSwitch() {
    if (intervalID != undefined) {
        clearInterval(intervalID);
    }
    intervalID = setInterval(autoSwitch, 7000);
}

function autoSwitch() {
    var nextID = currentId + 1;
    if (nextID > picLen-1) {
        nextID = nextID % picLen;
    }
    switchPic(nextID, true);
}

function switchPic(id, isAuto) {
    if (currentId == id) {
        return;
    }
    if (isAuto == undefined) {
        setAutoSwitch();
    }
    $("#noflash_img_" + currentId).hide();
    currentId = id;
    $("#noflash_img_" + id).css({ "opacity": 0, "display": "" }).animate({ "opacity": 1 }, 500);
}