window.onload = function() {
    init();

    //    var manager = new jsAnimManager(0);

    //    manager.createAnimObject('loadingScreen').add({
    //        property: Prop.opacity,
    //        from: 1,
    //        to: 0,
    //        duration: 1000,
    //        onComplete: function() { document.getElementById('loadingScreen').style.display = "none"; } 
    //    });
    document.getElementById('loadingScreen').style.display = "none";
    document.getElementById('MainContainer').style.display = "block";

    setBtmMenu();
    setContactForm();
    //setVideoSize();
};

function setContactForm() {
    var myWidth = document.getElementById('MainContainer').clientWidth;
    if (myWidth < 768) {
        document.getElementById('textboxComments').style.width = "200px";
    }
}

function setBtmMenu() {
    var myWidth = document.getElementById('MainContainer').clientWidth;

    if (myWidth < 768) {
        document.getElementById('Footer').style.display = "none";
        document.getElementById('FooterMobile').style.display = "block";
    }
    btmMenuTap('homeContainer');
};

/*
function setVideoSize() {
    var myWidth = document.getElementById('homeSide').offsetWidth;

    document.getElementById('video').style.width = myWidth + "px";

    var vidHeight = document.getElementById('video').clientHeight;

    document.getElementById('homeSide').style.marginTop = vidHeight + 20 + "px";
};*/

var backToggle = 0;

function showLoading() {
    document.getElementById('loading').style.display = "block";
};
function hideLoading() {
    document.getElementById('loading').style.display = "none";
};
function setResolutions() {
    var myWidth = document.getElementById('loadingScreen').clientWidth;
    
    if (myWidth <= 640) {
        //Set Chandalier image for devices
        document.getElementById('chandyImage').src = "images/Chandy-Sm.png";
    }
    else {
        document.getElementById('chandyImage').src = "images/Chandy-Lg.png";
    }
    document.getElementById('panel1').style.opacity = 1;
};

//************************************************
// CAPTCHA
//************************************************
//Created / Generates the captcha function    
function DrawCaptcha() {
    var a = Math.ceil(Math.random() * 10) + '';
    var b = Math.ceil(Math.random() * 10) + '';
    var c = Math.ceil(Math.random() * 10) + '';
    var d = Math.ceil(Math.random() * 10) + '';
    var e = Math.ceil(Math.random() * 10) + '';
    var f = Math.ceil(Math.random() * 10) + '';
    var g = Math.ceil(Math.random() * 10) + '';
    var code = a + ' ' + b + ' ' + ' ' + c + ' ' + d + ' ' + e + ' ' + f + ' ' + g;
    document.getElementById("txtCaptcha").value = code
}

// Validate the Entered input aganist the generated security code function   
function ValidCaptcha() {
    var str1 = removeSpaces(document.getElementById('txtCaptcha').value);
    var str2 = removeSpaces(document.getElementById('txtInput').value);
    if (str1 == str2) return true;
    return false;
}

// Remove the spaces from the entered and generated code
function removeSpaces(string) {
    return string.split(' ').join('');
}
function ShowHood() {
    showLoading();
    PageMethods.GetHoods("", MethodResultsGetHood);
}
function MethodResultsGetHood(ResultsString) {
    ResultsString = ResultsString + "<div class=\"spacer\"></div>";
    ResultsString = ResultsString + "<div><img style=\"height:300px\" src=\"images/Transparent.png\" /></div>";
    document.getElementById('hoodsScroller').innerHTML = ResultsString;
    refreshScrolls();
    hideLoading();
    //document.getElementById('homeContainer').style.display = "none";
    //document.getElementById('inventoryContainer').style.display = "block";
}


function ShowInventory() {
    showLoading();
    PageMethods.GetInventory("", MethodResultsGetInventory);
}
function MethodResultsGetInventory(ResultsString) {
    ResultsString = ResultsString + "<div class=\"spacer\"></div>";
    document.getElementById('inventoryScroller').innerHTML = ResultsString;
    refreshScrolls();
    hideLoading();
    //document.getElementById('homeContainer').style.display = "none";
    //document.getElementById('inventoryContainer').style.display = "block";
}
function ShowGallery() {
    showLoading();
    PageMethods.GetGalleryNew("", MethodResultsGetGallery);
}
function MethodResultsGetGallery(ResultsString) {
    ResultsString = ResultsString + "<div class=\"spacer\"></div>";
    document.getElementById('galleryScroller').innerHTML = ResultsString;
    refreshScrolls();
    hideLoading();
    Galleria.loadTheme('galleria/themes/folio/galleria.folio.min.js');
    $('#galleria').galleria({
        preload: 3,
        debug: false, 
        height:750,
        transition: 'fade'
    });
    //document.getElementById('homeContainer').style.display = "none";
    //document.getElementById('inventoryContainer').style.display = "block";
}

function ShowFeatures() {
    showLoading();
    PageMethods.GetFeatures("", MethodResultsGetFeatures);
}
function MethodResultsGetFeatures(ResultsString) {
    ResultsString = ResultsString + "<div class=\"spacer\"></div>";
    document.getElementById('featuresScroller').innerHTML = ResultsString;
    refreshScrolls();
    hideLoading();
    Galleria.loadTheme('galleria/themes/folio/galleria.folio.min.js');
    $('#galleria_features').galleria({
        preload: 3,
        debug: false, 
        height:750,
        transition: 'fade'
    });
    //document.getElementById('homeContainer').style.display = "none";
    //document.getElementById('inventoryContainer').style.display = "block";
}
//************************************************
// CAPTCHA
//************************************************

//************************************************
// Toggle Animations - Documentation at http://www.jsanim.com/
//************************************************
function fadeToggle(myToggle) {
    if (myToggle != "homeContainer") {
       // document.getElementById("video").style.display = "none";
    }
    if (myToggle == "inventoryContainer") {
        ShowInventory();
    }
    if (myToggle == "galleryContainer") {
        ShowGallery();
    }
    if (myToggle == "featuresContainer") {
        ShowFeatures();
    }
    if (myToggle == "hoodsContainer") {
        ShowHood();
    }
    
    var manager = new jsAnimManager(0);

    var menuBar = document.getElementById('menuBar').clientWidth;

    var homeDisplay = document.getElementById('homeContainer').style.display;
    var hoodsDisplay = document.getElementById('hoodsContainer').style.display;
    var galleryDisplay = document.getElementById('galleryContainer').style.display;
    var designerDisplay = document.getElementById('designerContainer').style.display;
    var plansDisplay = document.getElementById('plansContainer').style.display;
    var featuresDisplay = document.getElementById('featuresContainer').style.display;
    var inventoryDisplay = document.getElementById('inventoryContainer').style.display;
    var contactDisplay = document.getElementById('contactContainer').style.display;
    var aboutDisplay = document.getElementById('aboutContainer').style.display;

    if (myToggle != "toggleMenu") {
        var currentScreen;
        if (homeDisplay == "block") { currentScreen = 'homeContainer'; }
        if (hoodsDisplay == "block") { currentScreen = 'hoodsContainer'; }
        if (galleryDisplay == "block") { currentScreen = 'galleryContainer'; }
        if (designerDisplay == "block") { currentScreen = 'designerContainer'; }
        if (plansDisplay == "block") { currentScreen = 'plansContainer'; }
        if (featuresDisplay == "block") { currentScreen = 'featuresContainer'; }
        if (inventoryDisplay == "block") { currentScreen = 'inventoryContainer'; }
        if (contactDisplay == "block") { currentScreen = 'contactContainer'; }
        if (aboutDisplay == "block") { currentScreen = 'aboutContainer'; }

        document.getElementById(myToggle).style.display = "block";
        document.getElementById(currentScreen).style.display = "none";
    }
    if (menuBar != 0) {
        manager.createAnimObject('menuPanel').add({ property: Prop.left, to: -300, duration: 250 });
    }
    resetBtmMenu();
    refreshScrolls();
};
function showMenu() {
    var manager = new jsAnimManager(0);
    var menu = document.getElementById('menuPanel');
    
    menu.style.display = "block";
    menu.style.left = "-300px";
    menu.style.zIndex = "1000";

    manager.createAnimObject('menuPanel').add({ property: Prop.left, to: 0, duration: 250 });
};
//************************************************
// END - Toggle Animations
//************************************************

//************************************************
// Bottom Nav
//************************************************
function btmNav(newPage) {
    btmMenuTap(newPage);

    //Determine which child of "Content" is block, which would be the current page
    var myDivList = document.getElementById('Content');
    for (i = 0; i < myDivList.childNodes.length; i++) {
        if (myDivList.childNodes[i].nodeName == "DIV" && myDivList.childNodes[i].style.display == "block") {
            myDivList.childNodes[i].style.display = "none";
            break;
        }
    }

    document.getElementById(newPage).style.display = "block";

    refreshScrolls();
};

function btmMenuTap(newPage) {
    var myIcon = "";
    var myButton = "";
    var myText = "";
    var myBack = "";

    resetBtmMenu();
    if (newPage == "homeContainer") {
        myIcon = "images/Icon-Home-Over.png";
        myButton = "ImageButton1";
        myText = "Text1";
        myBack = "BtmMenuItem1";
    }
    if (newPage == "aboutContainer") {
        myIcon = "images/Icon-About-Over.png";
        myButton = "ImageButton2";
        myText = "Text2";
        myBack = "BtmMenuItem2";
    }
    if (newPage == "contactContainer") {
        myIcon = "images/Icon-Call-Over.png";
        myButton = "ImageButton3";
        myText = "Text3";
        myBack = "BtmMenuItem3";
    }

    document.getElementById(myButton).src = myIcon;
    document.getElementById(myText).style.color = "White";
    document.getElementById(myBack).style.background = "url(images/BtmMenuBack-Over.png) no-repeat fixed center center";
    document.getElementById(myBack).style.backgroundSize = "cover";
};

function resetBtmMenu() {
    //Reset all Bottom Menu Button Images
    document.getElementById('ImageButton1').src = "images/Icon-Home.png";
    document.getElementById('ImageButton2').src = "images/Icon-About.png";
    document.getElementById('ImageButton3').src = "images/Icon-Call.png";
    document.getElementById('ImageButton4').src = "images/Icon-Finance.png";

    //Reset all Bottom Menu Text Colors
    document.getElementById('Text1').style.color = "#c6c6c5";
    document.getElementById('Text2').style.color = "#c6c6c5";
    document.getElementById('Text3').style.color = "#c6c6c5";
    document.getElementById('Text4').style.color = "#c6c6c5";

    //Reset all the Background overlays
    document.getElementById('BtmMenuItem1').style.backgroundImage = "url(images/transparent.png)";
    document.getElementById('BtmMenuItem2').style.backgroundImage = "url(images/transparent.png)";
    document.getElementById('BtmMenuItem3').style.backgroundImage = "url(images/transparent.png)";
    document.getElementById('BtmMenuItem4').style.backgroundImage = "url(images/transparent.png)";
};
//************************************************
// END - Bottom Nav
//************************************************

//************************************************
// Slide Show
//************************************************
function switchSlides(myDirection) {
    var manager = new jsAnimManager(0);
    var myPanels = 13; //Specify the number of panels

    var panel1Opacity = document.getElementById('panel1').style.opacity;
    var panel2Opacity = document.getElementById('panel2').style.opacity;
    var panel3Opacity = document.getElementById('panel3').style.opacity;
    var panel4Opacity = document.getElementById('panel4').style.opacity;
    var panel5Opacity = document.getElementById('panel5').style.opacity;
    var panel6Opacity = document.getElementById('panel6').style.opacity;
    var panel7Opacity = document.getElementById('panel7').style.opacity;
    var panel8Opacity = document.getElementById('panel8').style.opacity;
    var panel9Opacity = document.getElementById('panel9').style.opacity;
    var panel10Opacity = document.getElementById('panel10').style.opacity;
    var panel11Opacity = document.getElementById('panel11').style.opacity;
    var panel12Opacity = document.getElementById('panel12').style.opacity;
    var panel13Opacity = document.getElementById('panel13').style.opacity;

    var currentPanel;
    if (panel1Opacity == 1) {currentPanel = 1;}
    if (panel2Opacity == 1) {currentPanel = 2;}
    if (panel3Opacity == 1) {currentPanel = 3;}
    if (panel4Opacity == 1) {currentPanel = 4;}
    if (panel5Opacity == 1) {currentPanel = 5;}
    if (panel6Opacity == 1) {currentPanel = 6;}
    if (panel7Opacity == 1) {currentPanel = 7;}
    if (panel8Opacity == 1) {currentPanel = 8;}
    if (panel9Opacity == 1) {currentPanel = 9;}
    if (panel10Opacity == 1) {currentPanel = 10;}
    if (panel11Opacity == 1) {currentPanel = 11;}
    if (panel12Opacity == 1) {currentPanel = 12;}
    if (panel13Opacity == 1) {currentPanel = 13;}

    switch (myDirection) {
        case "prev":
            switch (currentPanel) {
                case 1:
                    nextSlide('panel1', 'img1', 'img2', 'img3', 'img4', 'panel13', 'img49', 'img50', 'img51', 'img52');
                    break;
                case 2:
                    nextSlide('panel2', 'img5', 'img6', 'img7', 'img8', 'panel1', 'img1', 'img2', 'img3', 'img4');
                    break;
                case 3:
                    nextSlide('panel3', 'img9', 'img10', 'img11', 'img12', 'panel2', 'img5', 'img6', 'img7', 'img8');
                    break;
                case 4:
                    nextSlide('panel4', 'img13', 'img14', 'img15', 'img16', 'panel3', 'img9', 'img10', 'img11', 'img12');
                    break;
                case 5:
                    nextSlide('panel5', 'img17', 'img18', 'img19', 'img20', 'panel4', 'img13', 'img14', 'img15', 'img16');
                    break;
                case 6:
                    nextSlide('panel6', 'img21', 'img22', 'img23', 'img24', 'panel5', 'img17', 'img18', 'img19', 'img20');
                    break;
                case 7:
                    nextSlide('panel7', 'img25', 'img26', 'img27', 'img28', 'panel6', 'img21', 'img22', 'img23', 'img24');
                    break;
                case 8:
                    nextSlide('panel8', 'img29', 'img30', 'img31', 'img32', 'panel7', 'img25', 'img26', 'img27', 'img28');
                    break;
                case 9:
                    nextSlide('panel9', 'img33', 'img34', 'img35', 'img36', 'panel8', 'img29', 'img30', 'img31', 'img32');
                    break;
                case 10:
                    nextSlide('panel10', 'img37', 'img38', 'img39', 'img40', 'panel9', 'img33', 'img34', 'img35', 'img36');
                    break;
                case 11:
                    nextSlide('panel11', 'img41', 'img42', 'img43', 'img44', 'panel10', 'img33', 'img34', 'img35', 'img36');
                    break;
                case 12:
                    nextSlide('panel12', 'img45', 'img46', 'img47', 'img48', 'panel11', 'img37', 'img38', 'img39', 'img40');
                    break;
                case 13:
                    nextSlide('panel13', 'img49', 'img50', 'img51', 'img52', 'panel12', 'img41', 'img42', 'img43', 'img44');
                    break;
            }
            break;
        case "next":
            switch (currentPanel) {
                case 1:
                    nextSlide('panel1', 'img1', 'img2', 'img3', 'img4', 'panel2', 'img5', 'img6', 'img7', 'img8');
                    break;
                case 2:
                    nextSlide('panel2', 'img5', 'img6', 'img7', 'img8', 'panel3', 'img9', 'img10', 'img11', 'img12');
                    break;
                case 3:
                    nextSlide('panel3', 'img9', 'img10', 'img11', 'img12', 'panel4', 'img13', 'img14', 'img15', 'img16');
                    break;
                case 4:
                    nextSlide('panel4', 'img13', 'img14', 'img15', 'img16', 'panel5', 'img17', 'img18', 'img19', 'img20');
                    break;
                case 5:
                    nextSlide('panel5', 'img17', 'img18', 'img19', 'img20', 'panel6', 'img21', 'img22', 'img23', 'img24');
                    break;
                case 6:
                    nextSlide('panel6', 'img21', 'img22', 'img23', 'img24', 'panel7', 'img25', 'img26', 'img27', 'img28');
                    break;
                case 7:
                    nextSlide('panel7', 'img25', 'img26', 'img27', 'img28', 'panel8', 'img29', 'img30', 'img31', 'img32');
                    break;
                case 8:
                    nextSlide('panel8', 'img29', 'img30', 'img31', 'img32', 'panel9', 'img33', 'img34', 'img35', 'img36');
                    break;
                case 9:
                    nextSlide('panel9', 'img33', 'img34', 'img35', 'img36', 'panel10', 'img37', 'img38', 'img39', 'img40');
                    break;
                case 10:
                    nextSlide('panel10', 'img37', 'img38', 'img39', 'img40', 'panel11', 'img41', 'img42', 'img43', 'img44');
                    break;
                case 11:
                    nextSlide('panel11', 'img41', 'img42', 'img43', 'img44', 'panel12', 'img45', 'img46', 'img47', 'img48');
                    break;
                case 12:
                    nextSlide('panel12', 'img45', 'img46', 'img47', 'img48', 'panel13', 'img49', 'img50', 'img51', 'img52');
                    break;
                case 13:
                    nextSlide('panel13', 'img49', 'img50', 'img51', 'img52', 'panel1', 'img1', 'img2', 'img3', 'img4');
                    break;
            }
            break;
    }
};
function nextSlide(currentPanel, img1, img2, img3, img4, newPanel, img5, img6, img7, img8) {
    var manager = new jsAnimManager(0);

    document.getElementById(newPanel).style.display = "block";
    
    manager.createAnimObject(currentPanel).add({ property: Prop.opacity, from: 1, to: 0, duration: 750 });
    manager.createAnimObject(img1).add({ property: Prop.top, to: -230, duration: 250 });
    manager.createAnimObject(img2).add({ property: Prop.top, to: -230, duration: 400 });
    manager.createAnimObject(img3).add({ property: Prop.top, to: -230, duration: 550 });
    manager.createAnimObject(img4).add({ property: Prop.top, to: -230, duration: 700 });
    manager.createAnimObject(newPanel).add({ property: Prop.opacity, from: 0, to: 1, duration: 750, onComplete: function() { document.getElementById(currentPanel).style.display = "none"; } });
    manager.createAnimObject(img5).add({ property: Prop.top, to: 0, duration: 250 });
    manager.createAnimObject(img6).add({ property: Prop.top, to: 0, duration: 400 });
    manager.createAnimObject(img7).add({ property: Prop.top, to: 0, duration: 550 });
    manager.createAnimObject(img8).add({ property: Prop.top, to: 0, duration: 700 });
};
function picPopup(mySlide) {
    var myFullSize = mySlide;

    showLoading();
    myImage = new Image();
    myImage.src = myFullSize;

    myImage.onload = function() {
        hideLoading();

        document.getElementById('fullSlide').src = myFullSize;
        document.getElementById('slideScreen').style.opacity = 0;
        document.getElementById('slideScreen').style.display = "block";

        setTimeout(function() {
            var myWidth = document.getElementById('fullSlide').clientWidth;
            var myHeight = document.getElementById('fullSlide').clientHeight;

            //alert("Width: " + myWidth + " - Height: " + myHeight);

            document.getElementById('fullSlide').style.marginLeft = myWidth / 2 * -1 + "px";
            document.getElementById('fullSlide').style.marginTop = myHeight / 2 * -1 + "px";

            var xTop = document.getElementById('fullSlide').offsetTop + 10;
            var xLeft = document.getElementById('fullSlide').offsetLeft + myWidth - 15;

            document.getElementById('slideClose').style.top = xTop + "px";
            document.getElementById('slideClose').style.left = xLeft + "px";

            var manager = new jsAnimManager(0);

            var anim1 = manager.createAnimObject("slideScreen");

            anim1.add({
                property: Prop.opacity,
                from: 0,
                to: 1,
                duration: 250
            });
        }, 2000);
    }
};
function inventoryPopup(invAddress, invHood, invPlan, invPrice, invSF, invContact, invStatus, invNotes, invImg, obeo) {
    showLoading();
    document.getElementById('inventoryAddress').innerHTML = invAddress;
    document.getElementById('inventoryHood').innerHTML = "<span class=\"invLabel\">Neighborhood: </span>" + invHood;
    document.getElementById('inventoryPlan').innerHTML = "<span class=\"invLabel\">Plan: </span>" + invPlan;
    document.getElementById('inventoryPrice').innerHTML = "<span class=\"invLabel\">$</span>" + invPrice;
    document.getElementById('inventorySF').innerHTML = "<span class=\"invLabel\">Square Feet: </span>" + invSF;
    document.getElementById('inventoryContact').innerHTML = "<span class=\"invLabel\">Contact: </span>" + "<a href='mailto: " + invContact + "'>" + invContact + "</a>";
    document.getElementById('inventoryStatus').innerHTML = "<span class=\"invLabel\">Status: </span>" + invStatus;
    document.getElementById('inventorySRC').src = invImg;
    document.getElementById('inventoryNotes').innerHTML = "<br /><br />" + invNotes;
    if (obeo != '') {
        document.getElementById('inventoryObeo').innerHTML = "<a href=\"http://homesite.obeo.com/Viewer/Default.aspx?tourid=" + obeo + "&locale=en-US&refUrl=allenstylehomes.com\">Take the tour!</a>";
    }
    myImage = new Image();
    myImage.src = invImg;

    myImage.onload = function() {
        hideLoading();
        document.getElementById('inventoryViewContainer').style.opacity = 1;
        document.getElementById('inventoryViewContainer').style.display = "block";
    }
};
function planPopup(planName) {
    showLoading();

    var planImg;
    var planPhoto1;
    var planPhoto2;
    var planText;
    
    switch (planName) {
        case "Doyle":
            planImg = "images/Plan-Doyle.png";
            planPhoto1 = "images/Plan-Photo1-Doyle-Sm.jpg";
            planPhoto2 = "images/Plan-Photo2-Doyle-Sm.jpg";
            planText = "2415 Square Feet<br />• 3/4 Bedrooms<br />• Study  • Bonus Room<br />• 2 Bathrooms";
            break;
        case "Andrew":
            planImg = "images/Plan-Andrew.png";
            planPhoto1 = "";
            planPhoto2 = "";
            planText = "2415 Square Feet<br />• 3/4 Bedrooms<br />• Study  • Bonus Room<br />• 2 Bathrooms";
            break;
        case "Elizabeth":
            planImg = "images/Plan-Elizabeth.png";
            planPhoto1 = "";
            planPhoto2 = "";
            planText = "2432 Square Feet<br />• 3 Bedrooms<br />• Dining/Study  • 2 Domomg<br />• Game Room";
            break;
        case "Jacob":
            planImg = "images/Plan-Jacob.png";
            planPhoto1 = "";
            planPhoto2 = "";
            planText = "1849 Square Feet<br />• 3 Bedrooms plus Study<br />• 2 Bathrooms";
            break;
        case "Madison":
            planImg = "images/Plan-Madison.png";
            planPhoto1 = "";
            planPhoto2 = "";
            planText = "1849 Square Feet<br />• 3 Bedrooms plus Study<br />• 2 Bathrooms";
            break;
        case "Megan":
            planImg = "images/Plan-Megan.png";
            planPhoto1 = "";
            planPhoto2 = "";
            planText = "1923 Square Feet<br />• 3/4 Bedrooms<br />• 2 Bathrooms";
            break;
        case "Monroe":
            planImg = "images/Plan-Monroe.png";
            planPhoto1 = "";
            planPhoto2 = "";
            planText = "";
            break;
        case "Sydnee":
            planImg = "images/Plan-Sydnee.png";
            planPhoto1 = "";
            planPhoto2 = "";
            planText = "2202 Square Feet<br />• 3 Bedrooms<br />• Dining/Study<br />• 2.5 Bathrooms";
            break;
    }

    document.getElementById('planTitle').innerHTML = "The " + planName;
    document.getElementById('planSRC').src = planImg;
    document.getElementById('photo1').src = planPhoto1;
    document.getElementById('photo2').src = planPhoto2;
    document.getElementById('planText').innerHTML = planText;

    if (planPhoto1 == "") { document.getElementById('photo1').style.display = "none" }
    else { document.getElementById('photo1').style.display = "block" }

    if (planPhoto2 == "") { document.getElementById('photo2').style.display = "none" }
    else { document.getElementById('photo2').style.display = "block" }
    
    myImage = new Image();
    myImage.src = planImg;

    myImage.onload = function() {
        hideLoading();
        document.getElementById('planViewContainer').style.opacity = 1;
        document.getElementById('planViewContainer').style.display = "block";
    }
};
function closeSlide() {
    close("slideScreen", 100);
};
function closePlan() {
    close("planViewContainer", 10);
};
function closeInventory() {
    close("inventoryViewContainer", 10);
};
function close(myDiv, myDuration) {
    var manager = new jsAnimManager(0);

    var anim1 = manager.createAnimObject(myDiv);

    anim1.add({
        property: Prop.opacity,
        from: 1,
        to: 0,
        duration: myDuration,
        onComplete: function() { document.getElementById(myDiv).style.display = "none"; }
    });
};
//************************************************
// END - Slide Show
//************************************************

//************************************************
// Check Device Functions
//************************************************
var deviceIphone = "iphone";
var deviceIpod = "ipod";
var deviceIpad = "ipad";

//Initialize our user agent string to lower case.
var uagent = navigator.userAgent.toLowerCase();

//**************************
// Detects if the current device is an iPhone.
function DetectIphone() {
    if (uagent.search(deviceIphone) > -1) {
        return true;
    }
    if (uagent.search(deviceIpad) > -1) {
        return true;
    }
    if (uagent.search(deviceIpod) > -1) {
        return true;
    }
    else {
        return false;
    }
}
//************************************************
// Check Device Functions
//************************************************

//************************************************
// IE Browser detect from MSDN.com
//************************************************

function getInternetExplorerVersion()
// Returns the version of Internet Explorer or a -1
// (indicating the use of another browser).
{
    var rv = -1; // Return value assumes failure
    if (navigator.appName == 'Microsoft Internet Explorer') {
        var ua = navigator.userAgent;
        var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
        if (re.exec(ua) != null)
            rv = parseFloat(RegExp.$1);
    }
    return rv;
}

//************************************************
// End IE browser detect
//************************************************

// ************************************************************************
//  Popup Functions
// ************************************************************************
function showPopup() {
    document.getElementById('popupContainer').style.display = "block";
    popupLinks();
};
function hidePopup() {
    document.getElementById('popupContainer').style.display = "none";
};
// ************************************************************************
//  END - Popup Functions
// ************************************************************************





// ************************************************************************
// ************************************************************************
// ************************************************************************
//  Third Party included .js files
// ************************************************************************
// ************************************************************************
// ************************************************************************

// ************************************************************************
//  iScroll
// ************************************************************************
/*!
* iScroll Lite base on iScroll v4.1.6 ~ Copyright (c) 2011 Matteo Spinelli, http://cubiq.org
* Released under MIT license, http://cubiq.org/license
*/

(function() {
    var m = Math,
	vendor = (/webkit/i).test(navigator.appVersion) ? 'webkit' :
		(/firefox/i).test(navigator.userAgent) ? 'Moz' :
		'opera' in window ? 'O' : '',

    // Browser capabilities
	has3d = 'WebKitCSSMatrix' in window && 'm11' in new WebKitCSSMatrix(),
	hasTouch = 'ontouchstart' in window,
	hasTransform = vendor + 'Transform' in document.documentElement.style,
	isIDevice = (/iphone|ipad/gi).test(navigator.appVersion),
	isPlaybook = (/playbook/gi).test(navigator.appVersion),
	hasTransitionEnd = isIDevice || isPlaybook,
	nextFrame = (function() {
	    return window.requestAnimationFrame
			|| window.webkitRequestAnimationFrame
			|| window.mozRequestAnimationFrame
			|| window.oRequestAnimationFrame
			|| window.msRequestAnimationFrame
			|| function(callback) { return setTimeout(callback, 17); }
	})(),
	cancelFrame = (function() {
	    return window.cancelRequestAnimationFrame
			|| window.webkitCancelRequestAnimationFrame
			|| window.mozCancelRequestAnimationFrame
			|| window.oCancelRequestAnimationFrame
			|| window.msCancelRequestAnimationFrame
			|| clearTimeout
	})(),

    // Events
	RESIZE_EV = 'onorientationchange' in window ? 'orientationchange' : 'resize',
	START_EV = hasTouch ? 'touchstart' : 'mousedown',
	MOVE_EV = hasTouch ? 'touchmove' : 'mousemove',
	END_EV = hasTouch ? 'touchend' : 'mouseup',
	CANCEL_EV = hasTouch ? 'touchcancel' : 'mouseup',

    // Helpers
	trnOpen = 'translate' + (has3d ? '3d(' : '('),
	trnClose = has3d ? ',0)' : ')',

    // Constructor
	iScroll = function(el, options) {
	    var that = this,
			doc = document,
			i;

	    that.wrapper = typeof el == 'object' ? el : doc.getElementById(el);
	    that.wrapper.style.overflow = 'hidden';
	    that.scroller = that.wrapper.children[0];

	    // Default options
	    that.options = {
	        hScroll: true,
	        vScroll: true,
	        bounce: true,
	        bounceLock: false,
	        momentum: true,
	        lockDirection: true,
	        useTransform: true,
	        useTransition: false,

	        // Events
	        onRefresh: null,
	        onBeforeScrollStart: function(e) { e.preventDefault(); },
	        onScrollStart: null,
	        onBeforeScrollMove: null,
	        onScrollMove: null,
	        onBeforeScrollEnd: null,
	        onScrollEnd: null,
	        onTouchEnd: null,
	        onDestroy: null
	    };

	    // User defined options
	    for (i in options) that.options[i] = options[i];

	    // Normalize options
	    that.options.useTransform = hasTransform ? that.options.useTransform : false;
	    that.options.hScrollbar = that.options.hScroll && that.options.hScrollbar;
	    that.options.vScrollbar = that.options.vScroll && that.options.vScrollbar;
	    that.options.useTransition = hasTransitionEnd && that.options.useTransition;

	    // Set some default styles
	    that.scroller.style[vendor + 'TransitionProperty'] = that.options.useTransform ? '-' + vendor.toLowerCase() + '-transform' : 'top left';
	    that.scroller.style[vendor + 'TransitionDuration'] = '0';
	    that.scroller.style[vendor + 'TransformOrigin'] = '0 0';
	    if (that.options.useTransition) that.scroller.style[vendor + 'TransitionTimingFunction'] = 'cubic-bezier(0.33,0.66,0.66,1)';

	    if (that.options.useTransform) that.scroller.style[vendor + 'Transform'] = trnOpen + '0,0' + trnClose;
	    else that.scroller.style.cssText += ';position:absolute;top:0;left:0';

	    that.refresh();

	    that._bind(RESIZE_EV, window);
	    that._bind(START_EV);
	    if (!hasTouch) that._bind('mouseout', that.wrapper);
	};

    // Prototype
    iScroll.prototype = {
        enabled: true,
        x: 0,
        y: 0,
        steps: [],
        scale: 1,

        handleEvent: function(e) {
            var that = this;
            switch (e.type) {
                case START_EV:
                    if (!hasTouch && e.button !== 0) return;
                    that._start(e);
                    break;
                case MOVE_EV: that._move(e); break;
                case END_EV:
                case CANCEL_EV: that._end(e); break;
                case RESIZE_EV: that._resize(); break;
                case 'mouseout': that._mouseout(e); break;
                case 'webkitTransitionEnd': that._transitionEnd(e); break;
            }
        },

        _resize: function() {
            this.refresh();
        },

        _pos: function(x, y) {
            x = this.hScroll ? x : 0;
            y = this.vScroll ? y : 0;

            if (this.options.useTransform) {
                this.scroller.style[vendor + 'Transform'] = trnOpen + x + 'px,' + y + 'px' + trnClose + ' scale(' + this.scale + ')';
            } else {
                x = m.round(x);
                y = m.round(y);
                this.scroller.style.left = x + 'px';
                this.scroller.style.top = y + 'px';
            }

            this.x = x;
            this.y = y;
        },

        _start: function(e) {
            var that = this,
			point = hasTouch ? e.touches[0] : e,
			matrix, x, y;

            if (!that.enabled) return;

            if (that.options.onBeforeScrollStart) that.options.onBeforeScrollStart.call(that, e);

            if (that.options.useTransition) that._transitionTime(0);

            that.moved = false;
            that.animating = false;
            that.zoomed = false;
            that.distX = 0;
            that.distY = 0;
            that.absDistX = 0;
            that.absDistY = 0;
            that.dirX = 0;
            that.dirY = 0;

            if (that.options.momentum) {
                if (that.options.useTransform) {
                    // Very lame general purpose alternative to CSSMatrix
                    matrix = getComputedStyle(that.scroller, null)[vendor + 'Transform'].replace(/[^0-9-.,]/g, '').split(',');
                    x = matrix[4] * 1;
                    y = matrix[5] * 1;
                } else {
                    x = getComputedStyle(that.scroller, null).left.replace(/[^0-9-]/g, '') * 1;
                    y = getComputedStyle(that.scroller, null).top.replace(/[^0-9-]/g, '') * 1;
                }

                if (x != that.x || y != that.y) {
                    if (that.options.useTransition) that._unbind('webkitTransitionEnd');
                    else cancelFrame(that.aniTime);
                    that.steps = [];
                    that._pos(x, y);
                }
            }

            that.absStartX = that.x; // Needed by snap threshold
            that.absStartY = that.y;

            that.startX = that.x;
            that.startY = that.y;
            that.pointX = point.pageX;
            that.pointY = point.pageY;

            that.startTime = e.timeStamp || Date.now();

            if (that.options.onScrollStart) that.options.onScrollStart.call(that, e);

            that._bind(MOVE_EV);
            that._bind(END_EV);
            that._bind(CANCEL_EV);
        },

        _move: function(e) {
            var that = this,
			point = hasTouch ? e.touches[0] : e,
			deltaX = point.pageX - that.pointX,
			deltaY = point.pageY - that.pointY,
			newX = that.x + deltaX,
			newY = that.y + deltaY,
			timestamp = e.timeStamp || Date.now();

            if (that.options.onBeforeScrollMove) that.options.onBeforeScrollMove.call(that, e);

            that.pointX = point.pageX;
            that.pointY = point.pageY;

            // Slow down if outside of the boundaries
            if (newX > 0 || newX < that.maxScrollX) {
                newX = that.options.bounce ? that.x + (deltaX / 2) : newX >= 0 || that.maxScrollX >= 0 ? 0 : that.maxScrollX;
            }
            if (newY > 0 || newY < that.maxScrollY) {
                newY = that.options.bounce ? that.y + (deltaY / 2) : newY >= 0 || that.maxScrollY >= 0 ? 0 : that.maxScrollY;
            }

            if (that.absDistX < 6 && that.absDistY < 6) {
                that.distX += deltaX;
                that.distY += deltaY;
                that.absDistX = m.abs(that.distX);
                that.absDistY = m.abs(that.distY);

                return;
            }

            // Lock direction
            if (that.options.lockDirection) {
                if (that.absDistX > that.absDistY + 5) {
                    newY = that.y;
                    deltaY = 0;
                } else if (that.absDistY > that.absDistX + 5) {
                    newX = that.x;
                    deltaX = 0;
                }
            }

            that.moved = true;
            that._pos(newX, newY);
            that.dirX = deltaX > 0 ? -1 : deltaX < 0 ? 1 : 0;
            that.dirY = deltaY > 0 ? -1 : deltaY < 0 ? 1 : 0;

            if (timestamp - that.startTime > 300) {
                that.startTime = timestamp;
                that.startX = that.x;
                that.startY = that.y;
            }

            if (that.options.onScrollMove) that.options.onScrollMove.call(that, e);
        },

        _end: function(e) {
            if (hasTouch && e.touches.length != 0) return;

            var that = this,
			point = hasTouch ? e.changedTouches[0] : e,
			target, ev,
			momentumX = { dist: 0, time: 0 },
			momentumY = { dist: 0, time: 0 },
			duration = (e.timeStamp || Date.now()) - that.startTime,
			newPosX = that.x,
			newPosY = that.y,
			newDuration;

            that._unbind(MOVE_EV);
            that._unbind(END_EV);
            that._unbind(CANCEL_EV);

            if (that.options.onBeforeScrollEnd) that.options.onBeforeScrollEnd.call(that, e);

            if (!that.moved) {
                if (hasTouch) {
                    // Find the last touched element
                    target = point.target;
                    while (target.nodeType != 1) target = target.parentNode;

                    if (target.tagName != 'SELECT' && target.tagName != 'INPUT' && target.tagName != 'TEXTAREA') {
                        ev = document.createEvent('MouseEvents');
                        ev.initMouseEvent('click', true, true, e.view, 1,
						point.screenX, point.screenY, point.clientX, point.clientY,
						e.ctrlKey, e.altKey, e.shiftKey, e.metaKey,
						0, null);
                        ev._fake = true;
                        target.dispatchEvent(ev);
                    }
                }

                that._resetPos(200);

                if (that.options.onTouchEnd) that.options.onTouchEnd.call(that, e);
                return;
            }

            if (duration < 300 && that.options.momentum) {
                momentumX = newPosX ? that._momentum(newPosX - that.startX, duration, -that.x, that.scrollerW - that.wrapperW + that.x, that.options.bounce ? that.wrapperW : 0) : momentumX;
                momentumY = newPosY ? that._momentum(newPosY - that.startY, duration, -that.y, (that.maxScrollY < 0 ? that.scrollerH - that.wrapperH + that.y : 0), that.options.bounce ? that.wrapperH : 0) : momentumY;

                newPosX = that.x + momentumX.dist;
                newPosY = that.y + momentumY.dist;

                if ((that.x > 0 && newPosX > 0) || (that.x < that.maxScrollX && newPosX < that.maxScrollX)) momentumX = { dist: 0, time: 0 };
                if ((that.y > 0 && newPosY > 0) || (that.y < that.maxScrollY && newPosY < that.maxScrollY)) momentumY = { dist: 0, time: 0 };
            }

            if (momentumX.dist || momentumY.dist) {
                newDuration = m.max(m.max(momentumX.time, momentumY.time), 10);

                that.scrollTo(newPosX, newPosY, newDuration);

                if (that.options.onTouchEnd) that.options.onTouchEnd.call(that, e);
                return;
            }

            that._resetPos(200);
            if (that.options.onTouchEnd) that.options.onTouchEnd.call(that, e);
        },

        _resetPos: function(time) {
            var that = this,
			resetX = that.x >= 0 ? 0 : that.x < that.maxScrollX ? that.maxScrollX : that.x,
			resetY = that.y >= 0 || that.maxScrollY > 0 ? 0 : that.y < that.maxScrollY ? that.maxScrollY : that.y;

            if (resetX == that.x && resetY == that.y) {
                if (that.moved) {
                    if (that.options.onScrollEnd) that.options.onScrollEnd.call(that); 	// Execute custom code on scroll end
                    that.moved = false;
                }

                return;
            }

            that.scrollTo(resetX, resetY, time || 0);
        },

        _mouseout: function(e) {
            var t = e.relatedTarget;

            if (!t) {
                this._end(e);
                return;
            }

            while (t = t.parentNode) if (t == this.wrapper) return;

            this._end(e);
        },

        _transitionEnd: function(e) {
            var that = this;

            if (e.target != that.scroller) return;

            that._unbind('webkitTransitionEnd');

            that._startAni();
        },

        /**
        *
        * Utilities
        *
        */
        _startAni: function() {
            var that = this,
			startX = that.x, startY = that.y,
			startTime = Date.now(),
			step, easeOut;

            if (that.animating) return;

            if (!that.steps.length) {
                that._resetPos(400);
                return;
            }

            step = that.steps.shift();

            if (step.x == startX && step.y == startY) step.time = 0;

            that.animating = true;
            that.moved = true;

            if (that.options.useTransition) {
                that._transitionTime(step.time);
                that._pos(step.x, step.y);
                that.animating = false;
                if (step.time) that._bind('webkitTransitionEnd');
                else that._resetPos(0);
                return;
            }

            (function animate() {
                var now = Date.now(),
				newX, newY;

                if (now >= startTime + step.time) {
                    that._pos(step.x, step.y);
                    that.animating = false;
                    if (that.options.onAnimationEnd) that.options.onAnimationEnd.call(that); 		// Execute custom code on animation end
                    that._startAni();
                    return;
                }

                now = (now - startTime) / step.time - 1;
                easeOut = m.sqrt(1 - now * now);
                newX = (step.x - startX) * easeOut + startX;
                newY = (step.y - startY) * easeOut + startY;
                that._pos(newX, newY);
                if (that.animating) that.aniTime = nextFrame(animate);
            })();
        },

        _transitionTime: function(time) {
            this.scroller.style[vendor + 'TransitionDuration'] = time + 'ms';
        },

        _momentum: function(dist, time, maxDistUpper, maxDistLower, size) {
            var deceleration = 0.0006,
			speed = m.abs(dist) / time,
			newDist = (speed * speed) / (2 * deceleration),
			newTime = 0, outsideDist = 0;

            // Proportinally reduce speed if we are outside of the boundaries 
            if (dist > 0 && newDist > maxDistUpper) {
                outsideDist = size / (6 / (newDist / speed * deceleration));
                maxDistUpper = maxDistUpper + outsideDist;
                speed = speed * maxDistUpper / newDist;
                newDist = maxDistUpper;
            } else if (dist < 0 && newDist > maxDistLower) {
                outsideDist = size / (6 / (newDist / speed * deceleration));
                maxDistLower = maxDistLower + outsideDist;
                speed = speed * maxDistLower / newDist;
                newDist = maxDistLower;
            }

            newDist = newDist * (dist < 0 ? -1 : 1);
            newTime = speed / deceleration;

            return { dist: newDist, time: m.round(newTime) };
        },

        _offset: function(el) {
            var left = -el.offsetLeft,
			top = -el.offsetTop;

            while (el = el.offsetParent) {
                left -= el.offsetLeft;
                top -= el.offsetTop;
            }

            return { left: left, top: top };
        },

        _bind: function(type, el, bubble) {
            (el || this.scroller).addEventListener(type, this, !!bubble);
        },

        _unbind: function(type, el, bubble) {
            (el || this.scroller).removeEventListener(type, this, !!bubble);
        },


        /**
        *
        * Public methods
        *
        */
        destroy: function() {
            var that = this;

            that.scroller.style[vendor + 'Transform'] = '';

            // Remove the event listeners
            that._unbind(RESIZE_EV, window);
            that._unbind(START_EV);
            that._unbind(MOVE_EV);
            that._unbind(END_EV);
            that._unbind(CANCEL_EV);
            that._unbind('mouseout', that.wrapper);
            if (that.options.useTransition) that._unbind('webkitTransitionEnd');

            if (that.options.onDestroy) that.options.onDestroy.call(that);
        },

        refresh: function() {
            var that = this,
			offset;

            that.wrapperW = that.wrapper.clientWidth;
            that.wrapperH = that.wrapper.clientHeight;

            that.scrollerW = that.scroller.offsetWidth;
            that.scrollerH = that.scroller.offsetHeight;
            that.maxScrollX = that.wrapperW - that.scrollerW;
            that.maxScrollY = that.wrapperH - that.scrollerH;
            that.dirX = 0;
            that.dirY = 0;

            that.hScroll = that.options.hScroll && that.maxScrollX < 0;
            that.vScroll = that.options.vScroll && (!that.options.bounceLock && !that.hScroll || that.scrollerH > that.wrapperH);

            offset = that._offset(that.wrapper);
            that.wrapperOffsetLeft = -offset.left;
            that.wrapperOffsetTop = -offset.top;


            that.scroller.style[vendor + 'TransitionDuration'] = '0';

            that._resetPos(200);
        },

        scrollTo: function(x, y, time, relative) {
            var that = this,
			step = x,
			i, l;

            that.stop();

            if (!step.length) step = [{ x: x, y: y, time: time, relative: relative}];

            for (i = 0, l = step.length; i < l; i++) {
                if (step[i].relative) { step[i].x = that.x - step[i].x; step[i].y = that.y - step[i].y; }
                that.steps.push({ x: step[i].x, y: step[i].y, time: step[i].time || 0 });
            }

            that._startAni();
        },

        scrollToElement: function(el, time) {
            var that = this, pos;
            el = el.nodeType ? el : that.scroller.querySelector(el);
            if (!el) return;

            pos = that._offset(el);
            pos.left += that.wrapperOffsetLeft;
            pos.top += that.wrapperOffsetTop;

            pos.left = pos.left > 0 ? 0 : pos.left < that.maxScrollX ? that.maxScrollX : pos.left;
            pos.top = pos.top > 0 ? 0 : pos.top < that.maxScrollY ? that.maxScrollY : pos.top;
            time = time === undefined ? m.max(m.abs(pos.left) * 2, m.abs(pos.top) * 2) : time;

            that.scrollTo(pos.left, pos.top, time);
        },

        disable: function() {
            this.stop();
            this._resetPos(0);
            this.enabled = false;

            // If disabled after touchstart we make sure that there are no left over events
            this._unbind(MOVE_EV);
            this._unbind(END_EV);
            this._unbind(CANCEL_EV);
        },

        enable: function() {
            this.enabled = true;
        },

        stop: function() {
            cancelFrame(this.aniTime);
            this.steps = [];
            this.moved = false;
            this.animating = false;
        }
    };

    if (typeof exports !== 'undefined') exports.iScroll = iScroll;
    else window.iScroll = iScroll;

})();
// ************************************************************************
//  END iScroll
// ************************************************************************

// ************************************************************************
//  Add 2 Home
// ************************************************************************
/**
* 
* * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* Copyright (c) 2011 Matteo Spinelli, http://cubiq.org/
* Released under MIT license
* http://cubiq.org/dropbox/mit-license.txt
* 
* Version 1.0.1 - Last updated: 2011.02.05
* 
* * * * * * * * * * * * * * * * * * * * * * * * * * * *
* 
*/
; (function() {
    if (navigator.appName != "Microsoft Internet Explorer") {
        var nav = navigator,
	isIDevice = (/iphone|ipod|ipad/gi).test(nav.platform),
	isIPad = (/ipad/gi).test(nav.platform),
	isRetina = 'devicePixelRatio' in window && window.devicePixelRatio > 1,
	isSafari = nav.appVersion.match(/Safari/gi),
	hasHomescreen = 'standalone' in nav && isIDevice,
	isStandalone = hasHomescreen && nav.standalone,
	OSVersion = nav.appVersion.match(/OS \d+_\d+/g),
	platform = nav.platform.split(' ')[0],
	language = nav.language.replace('-', '_'),
	startY = startX = 0,
	expired = localStorage.getItem('_addToHome'),
	theInterval, closeTimeout, el, i, l,
	options = {
	    animationIn: 'drop', 	// drop || bubble || fade
	    animationOut: 'fade', 	// drop || bubble || fade
	    startDelay: 2000, 		// 2 seconds from page load before the balloon appears
	    lifespan: 20000, 		// 20 seconds before it is automatically destroyed
	    bottomOffset: 14, 		// Distance of the balloon from bottom
	    expire: 0, 				// Minutes to wait before showing the popup again (0 = always displayed)
	    message: '', 			// Customize your message or force a language ('' = automatic)
	    touchIcon: false, 		// Display the touch icon
	    arrow: true, 			// Display the balloon arrow
	    iterations: 100				// Internal/debug use
	},
        /* Message in various languages, en_us is the default if a language does not exist */
	intl = {
	    ca_es: 'Per instal·lar aquesta aplicació al vostre %device premeu `%icon` i llavors `Afegir a pantalla d\'inici`',
	    da_dk: 'Tilføj denne side til din %device: tryk på `%icon` og derefter `<strong>Tilføj til hjemmeskærm</strong>`.',
	    de_de: 'Installieren Sie diese App auf Ihrem %device: `%icon` antippen und dann `<strong>Zum Home-Bildschirm</strong>`.',
	    el_gr: '????????????? ????? ??? ???????? ???? ??????? ??? %device: `%icon` ???? ?????? `<strong>???????? ?? ????????</strong>`.',
	    en_us: 'For the full app and best experiance, install this web app on your %device: tap `%icon` and then `<strong>Add to Home Screen</strong>`.',
	    es_es: 'Para instalar esta app en su %device, pulse `%icon` y seleccione `<strong>Añadir a pantalla de inicio</strong>`.',
	    fr_fr: 'Ajoutez cette application sur votre %device en cliquant sur `%icon`, puis `<strong>Ajouter à l\'écran d\'accueil</strong>`.',
	    he_il: '<span dir="rtl">???? ???????? ?? ?? ?-%device ???: ??? `%icon` ??? `<strong>???? ???? ????</strong>`.</span>',
	    it_it: 'Installa questa applicazione sul tuo %device: premi su `%icon` e poi `<strong>Aggiungi a Home</strong>`.',
	    ja_jp: '?????????????%device???????????`%icon`??????`<strong>????????</strong>`?????????',
	    ko_kr: '%device? ??? ????? %icon? ?? ? "???? ??"? ?????',
	    nl_nl: 'Installeer deze webapp op uw %device: tik `%icon` en dan `<strong>Zet in beginscherm</strong>`.',
	    pt_br: 'Instale este web app em seu %device: aperte `%icon` e selecione `<strong>Adicionar à Tela Inicio</strong>`.',
	    pt_pt: 'Para instalar esta aplicação no seu %device, prima o `%icon` e depois o `<strong>Adicionar ao ecrã principal</strong>`.',
	    sv_se: 'Lägg till denna webbapplikation på din %device: tryck på `%icon` och därefter `<strong>Lägg till på hemskärmen</strong>`.'
	};

        OSVersion = OSVersion ? OSVersion[0].replace(/[^\d_]/g, '').replace('_', '.') * 1 : 0;
        expired = expired == 'null' ? 0 : expired * 1;

        // Merge options
        if (window.addToHomeConfig) {
            for (i in window.addToHomeConfig) {
                options[i] = window.addToHomeConfig[i];
            }
        }

        // Is it expired?
        if (!options.expire || expired < new Date().getTime()) {
            expired = 0;
        }

        /* Bootstrap */
        if (hasHomescreen && !expired && !isStandalone && isSafari) {
            document.addEventListener('DOMContentLoaded', ready, false);
            window.addEventListener('load', loaded, false);
        }


        /* on DOM ready */
        function ready() {
            document.removeEventListener('DOMContentLoaded', ready, false);

            var div = document.createElement('div'),
		close,
		link = options.touchIcon ? document.querySelectorAll('head link[rel=apple-touch-icon],head link[rel=apple-touch-icon-precomposed]') : [],
		sizes, touchIcon = '';

            div.id = 'addToHomeScreen';
            div.style.cssText += 'position:absolute;-webkit-transition-property:-webkit-transform,opacity;-webkit-transition-duration:0;-webkit-transform:translate3d(0,0,0);';
            div.style.left = '-9999px'; 	// Hide from view at startup

            // Localize message
            if (options.message in intl) {		// You may force a language despite the user's locale
                language = options.message;
                options.message = '';
            }
            if (options.message == '') {		// We look for a suitable language (defaulted to en_us)
                options.message = language in intl ? intl[language] : intl['en_us'];
            }

            // Search for the apple-touch-icon
            if (link.length) {
                for (i = 0, l = link.length; i < l; i++) {
                    sizes = link[i].getAttribute('sizes');

                    if (sizes) {
                        if (isRetina && sizes == '114x114') {
                            touchIcon = link[i].href;
                            break;
                        }
                    } else {
                        touchIcon = link[i].href;
                    }
                }

                touchIcon = '<span style="background-image:url(' + touchIcon + ')" class="touchIcon"></span>';
            }

            div.className = (isIPad ? 'ipad' : 'iphone') + (touchIcon ? ' wide' : '');
            div.innerHTML = touchIcon + options.message.replace('%device', platform).replace('%icon', OSVersion >= 4.2 ? '<span class="share"></span>' : '<span class="plus">+</span>') + (options.arrow ? '<span class="arrow"></span>' : '') + '<span class="close">×</span>';

            document.body.appendChild(div);
            el = div;

            // Add the close action
            close = el.querySelector('.close');
            if (close) close.addEventListener('click', addToHomeClose, false);

            // Add expire date to the popup
            if (options.expire) localStorage.setItem('_addToHome', new Date().getTime() + options.expire * 60 * 1000);
        }


        /* on window load */
        function loaded() {
            window.removeEventListener('load', loaded, false);

            setTimeout(function() {
                var duration;

                startY = isIPad ? window.scrollY : window.innerHeight + window.scrollY;
                startX = isIPad ? window.scrollX : Math.round((window.innerWidth - el.offsetWidth) / 2) + window.scrollX;

                el.style.top = isIPad ? startY + options.bottomOffset + 'px' : startY - el.offsetHeight - options.bottomOffset + 'px';
                el.style.left = isIPad ? startX + 208 - Math.round(el.offsetWidth / 2) + 'px' : startX + 'px';

                switch (options.animationIn) {
                    case 'drop':
                        if (isIPad) {
                            duration = '0.6s';
                            el.style.webkitTransform = 'translate3d(0,' + -(window.scrollY + options.bottomOffset + el.offsetHeight) + 'px,0)';
                        } else {
                            duration = '0.9s';
                            el.style.webkitTransform = 'translate3d(0,' + -(startY + options.bottomOffset) + 'px,0)';
                        }
                        break;
                    case 'bubble':
                        if (isIPad) {
                            duration = '0.6s';
                            el.style.opacity = '0'
                            el.style.webkitTransform = 'translate3d(0,' + (startY + 50) + 'px,0)';
                        } else {
                            duration = '0.6s';
                            el.style.webkitTransform = 'translate3d(0,' + (el.offsetHeight + options.bottomOffset + 50) + 'px,0)';
                        }
                        break;
                    default:
                        duration = '1s';
                        el.style.opacity = '0';
                }

                setTimeout(function() {
                    el.style.webkitTransitionDuration = duration;
                    el.style.opacity = '1';
                    el.style.webkitTransform = 'translate3d(0,0,0)';
                    el.addEventListener('webkitTransitionEnd', transitionEnd, false);
                }, 0);

                closeTimeout = setTimeout(addToHomeClose, options.lifespan);
            }, options.startDelay);
        }

        function transitionEnd() {
            el.removeEventListener('webkitTransitionEnd', transitionEnd, false);
            el.style.webkitTransitionProperty = '-webkit-transform';
            el.style.webkitTransitionDuration = '0.2s';

            if (closeTimeout) {		// Standard loop
                clearInterval(theInterval);
                theInterval = setInterval(setPosition, options.iterations);
            } else {				// We are closing
                el.parentNode.removeChild(el);
            }
        }

        function setPosition() {
            var matrix = new WebKitCSSMatrix(window.getComputedStyle(el, null).webkitTransform),
		posY = isIPad ? window.scrollY - startY : window.scrollY + window.innerHeight - startY,
		posX = isIPad ? window.scrollX - startX : window.scrollX + Math.round((window.innerWidth - el.offsetWidth) / 2) - startX;

            if (posY == matrix.m42 && posX == matrix.m41) return;

            clearInterval(theInterval);
            el.removeEventListener('webkitTransitionEnd', transitionEnd, false);
            //	el.style.webkitTransitionDuration = '0';

            setTimeout(function() {
                el.addEventListener('webkitTransitionEnd', transitionEnd, false);
                //		el.style.webkitTransitionDuration = '0.2s';
                el.style.webkitTransform = 'translate3d(' + posX + 'px,' + posY + 'px,0)';
            }, 0);
        }

        function addToHomeClose() {
            clearInterval(theInterval);
            clearTimeout(closeTimeout);
            closeTimeout = null;
            el.removeEventListener('webkitTransitionEnd', transitionEnd, false);

            var posY = isIPad ? window.scrollY - startY : window.scrollY + window.innerHeight - startY,
		posX = isIPad ? window.scrollX - startX : window.scrollX + Math.round((window.innerWidth - el.offsetWidth) / 2) - startX,
		opacity = '1',
		duration = '0',
		close = el.querySelector('.close');

            if (close) close.removeEventListener('click', addToHomeClose, false);

            el.style.webkitTransitionProperty = '-webkit-transform,opacity';

            switch (options.animationOut) {
                case 'drop':
                    if (isIPad) {
                        duration = '0.4s';
                        opacity = '0';
                        posY = posY + 50;
                    } else {
                        duration = '0.6s';
                        posY = posY + el.offsetHeight + options.bottomOffset + 50;
                    }
                    break;
                case 'bubble':
                    if (isIPad) {
                        duration = '0.8s';
                        posY = posY - el.offsetHeight - options.bottomOffset - 50;
                    } else {
                        duration = '0.4s';
                        opacity = '0';
                        posY = posY - 50;
                    }
                    break;
                default:
                    duration = '0.8s';
                    opacity = '0';
            }

            el.addEventListener('webkitTransitionEnd', transitionEnd, false);
            el.style.opacity = opacity;
            el.style.webkitTransitionDuration = duration;
            el.style.webkitTransform = 'translate3d(' + posX + 'px,' + posY + 'px,0)';
        }

        /* Public function */
        window.addToHomeClose = addToHomeClose;
    }
})();
// ************************************************************************
//  END Add 2 Home
// ************************************************************************

// Modernizr v1.7  www.modernizr.com
// PhoneID Library
window.Modernizr = function(a, b, c) { function G() { e.input = function(a) { for (var b = 0, c = a.length; b < c; b++) t[a[b]] = !!(a[b] in l); return t } ("autocomplete autofocus list placeholder max min multiple pattern required step".split(" ")), e.inputtypes = function(a) { for (var d = 0, e, f, h, i = a.length; d < i; d++) l.setAttribute("type", f = a[d]), e = l.type !== "text", e && (l.value = m, l.style.cssText = "position:absolute;visibility:hidden;", /^range$/.test(f) && l.style.WebkitAppearance !== c ? (g.appendChild(l), h = b.defaultView, e = h.getComputedStyle && h.getComputedStyle(l, null).WebkitAppearance !== "textfield" && l.offsetHeight !== 0, g.removeChild(l)) : /^(search|tel)$/.test(f) || (/^(url|email)$/.test(f) ? e = l.checkValidity && l.checkValidity() === !1 : /^color$/.test(f) ? (g.appendChild(l), g.offsetWidth, e = l.value != m, g.removeChild(l)) : e = l.value != m)), s[a[d]] = !!e; return s } ("search tel url email datetime date month week time datetime-local number range color".split(" ")) } function F(a, b) { var c = a.charAt(0).toUpperCase() + a.substr(1), d = (a + " " + p.join(c + " ") + c).split(" "); return !!E(d, b) } function E(a, b) { for (var d in a) if (k[a[d]] !== c && (!b || b(a[d], j))) return !0 } function D(a, b) { return ("" + a).indexOf(b) !== -1 } function C(a, b) { return typeof a === b } function B(a, b) { return A(o.join(a + ";") + (b || "")) } function A(a) { k.cssText = a } var d = "1.7", e = {}, f = !0, g = b.documentElement, h = b.head || b.getElementsByTagName("head")[0], i = "modernizr", j = b.createElement(i), k = j.style, l = b.createElement("input"), m = ":)", n = Object.prototype.toString, o = " -webkit- -moz- -o- -ms- -khtml- ".split(" "), p = "Webkit Moz O ms Khtml".split(" "), q = { svg: "http://www.w3.org/2000/svg" }, r = {}, s = {}, t = {}, u = [], v, w = function(a) { var c = b.createElement("style"), d = b.createElement("div"), e; c.textContent = a + "{#modernizr{height:3px}}", h.appendChild(c), d.id = "modernizr", g.appendChild(d), e = d.offsetHeight === 3, c.parentNode.removeChild(c), d.parentNode.removeChild(d); return !!e }, x = function() { function d(d, e) { e = e || b.createElement(a[d] || "div"); var f = (d = "on" + d) in e; f || (e.setAttribute || (e = b.createElement("div")), e.setAttribute && e.removeAttribute && (e.setAttribute(d, ""), f = C(e[d], "function"), C(e[d], c) || (e[d] = c), e.removeAttribute(d))), e = null; return f } var a = { select: "input", change: "input", submit: "form", reset: "form", error: "img", load: "img", abort: "img" }; return d } (), y = ({}).hasOwnProperty, z; C(y, c) || C(y.call, c) ? z = function(a, b) { return b in a && C(a.constructor.prototype[b], c) } : z = function(a, b) { return y.call(a, b) }, r.flexbox = function() { function c(a, b, c, d) { a.style.cssText = o.join(b + ":" + c + ";") + (d || "") } function a(a, b, c, d) { b += ":", a.style.cssText = (b + o.join(c + ";" + b)).slice(0, -b.length) + (d || "") } var d = b.createElement("div"), e = b.createElement("div"); a(d, "display", "box", "width:42px;padding:0;"), c(e, "box-flex", "1", "width:10px;"), d.appendChild(e), g.appendChild(d); var f = e.offsetWidth === 42; d.removeChild(e), g.removeChild(d); return f }, r.canvas = function() { var a = b.createElement("canvas"); return a.getContext && a.getContext("2d") }, r.canvastext = function() { return e.canvas && C(b.createElement("canvas").getContext("2d").fillText, "function") }, r.webgl = function() { return !!a.WebGLRenderingContext }, r.touch = function() { return "ontouchstart" in a || w("@media (" + o.join("touch-enabled),(") + "modernizr)") }, r.geolocation = function() { return !!navigator.geolocation }, r.postmessage = function() { return !!a.postMessage }, r.websqldatabase = function() { var b = !!a.openDatabase; return b }, r.indexedDB = function() { for (var b = -1, c = p.length; ++b < c; ) { var d = p[b].toLowerCase(); if (a[d + "_indexedDB"] || a[d + "IndexedDB"]) return !0 } return !1 }, r.hashchange = function() { return x("hashchange", a) && (b.documentMode === c || b.documentMode > 7) }, r.history = function() { return !!(a.history && history.pushState) }, r.draganddrop = function() { return x("dragstart") && x("drop") }, r.websockets = function() { return "WebSocket" in a }, r.rgba = function() { A("background-color:rgba(150,255,150,.5)"); return D(k.backgroundColor, "rgba") }, r.hsla = function() { A("background-color:hsla(120,40%,100%,.5)"); return D(k.backgroundColor, "rgba") || D(k.backgroundColor, "hsla") }, r.multiplebgs = function() { A("background:url(//:),url(//:),red url(//:)"); return (new RegExp("(url\\s*\\(.*?){3}")).test(k.background) }, r.backgroundsize = function() { return F("backgroundSize") }, r.borderimage = function() { return F("borderImage") }, r.borderradius = function() { return F("borderRadius", "", function(a) { return D(a, "orderRadius") }) }, r.boxshadow = function() { return F("boxShadow") }, r.textshadow = function() { return b.createElement("div").style.textShadow === "" }, r.opacity = function() { B("opacity:.55"); return /^0.55$/.test(k.opacity) }, r.cssanimations = function() { return F("animationName") }, r.csscolumns = function() { return F("columnCount") }, r.cssgradients = function() { var a = "background-image:", b = "gradient(linear,left top,right bottom,from(#9f9),to(white));", c = "linear-gradient(left top,#9f9, white);"; A((a + o.join(b + a) + o.join(c + a)).slice(0, -a.length)); return D(k.backgroundImage, "gradient") }, r.cssreflections = function() { return F("boxReflect") }, r.csstransforms = function() { return !!E(["transformProperty", "WebkitTransform", "MozTransform", "OTransform", "msTransform"]) }, r.csstransforms3d = function() { var a = !!E(["perspectiveProperty", "WebkitPerspective", "MozPerspective", "OPerspective", "msPerspective"]); a && "webkitPerspective" in g.style && (a = w("@media (" + o.join("transform-3d),(") + "modernizr)")); return a }, r.csstransitions = function() { return F("transitionProperty") }, r.fontface = function() { var a, c, d = h || g, e = b.createElement("style"), f = b.implementation || { hasFeature: function() { return !1 } }; e.type = "text/css", d.insertBefore(e, d.firstChild), a = e.sheet || e.styleSheet; var i = f.hasFeature("CSS2", "") ? function(b) { if (!a || !b) return !1; var c = !1; try { a.insertRule(b, 0), c = /src/i.test(a.cssRules[0].cssText), a.deleteRule(a.cssRules.length - 1) } catch (d) { } return c } : function(b) { if (!a || !b) return !1; a.cssText = b; return a.cssText.length !== 0 && /src/i.test(a.cssText) && a.cssText.replace(/\r+|\n+/g, "").indexOf(b.split(" ")[0]) === 0 }; c = i('@font-face { font-family: "font"; src: url(data:,); }'), d.removeChild(e); return c }, r.video = function() { var a = b.createElement("video"), c = !!a.canPlayType; if (c) { c = new Boolean(c), c.ogg = a.canPlayType('video/ogg; codecs="theora"'); var d = 'video/mp4; codecs="avc1.42E01E'; c.h264 = a.canPlayType(d + '"') || a.canPlayType(d + ', mp4a.40.2"'), c.webm = a.canPlayType('video/webm; codecs="vp8, vorbis"') } return c }, r.audio = function() { var a = b.createElement("audio"), c = !!a.canPlayType; c && (c = new Boolean(c), c.ogg = a.canPlayType('audio/ogg; codecs="vorbis"'), c.mp3 = a.canPlayType("audio/mpeg;"), c.wav = a.canPlayType('audio/wav; codecs="1"'), c.m4a = a.canPlayType("audio/x-m4a;") || a.canPlayType("audio/aac;")); return c }, r.localstorage = function() { try { return !!localStorage.getItem } catch (a) { return !1 } }, r.sessionstorage = function() { try { return !!sessionStorage.getItem } catch (a) { return !1 } }, r.webWorkers = function() { return !!a.Worker }, r.applicationcache = function() { return !!a.applicationCache }, r.svg = function() { return !!b.createElementNS && !!b.createElementNS(q.svg, "svg").createSVGRect }, r.inlinesvg = function() { var a = b.createElement("div"); a.innerHTML = "<svg/>"; return (a.firstChild && a.firstChild.namespaceURI) == q.svg }, r.smil = function() { return !!b.createElementNS && /SVG/.test(n.call(b.createElementNS(q.svg, "animate"))) }, r.svgclippaths = function() { return !!b.createElementNS && /SVG/.test(n.call(b.createElementNS(q.svg, "clipPath"))) }; for (var H in r) z(r, H) && (v = H.toLowerCase(), e[v] = r[H](), u.push((e[v] ? "" : "no-") + v)); e.input || G(), e.crosswindowmessaging = e.postmessage, e.historymanagement = e.history, e.addTest = function(a, b) { a = a.toLowerCase(); if (!e[a]) { b = !!b(), g.className += " " + (b ? "" : "no-") + a, e[a] = b; return e } }, A(""), j = l = null, f && a.attachEvent && function() { var a = b.createElement("div"); a.innerHTML = "<elem></elem>"; return a.childNodes.length !== 1 } () && function(a, b) { function p(a, b) { var c = -1, d = a.length, e, f = []; while (++c < d) e = a[c], (b = e.media || b) != "screen" && f.push(p(e.imports, b), e.cssText); return f.join("") } function o(a) { var b = -1; while (++b < e) a.createElement(d[b]) } var c = "abbr|article|aside|audio|canvas|details|figcaption|figure|footer|header|hgroup|mark|meter|nav|output|progress|section|summary|time|video", d = c.split("|"), e = d.length, f = new RegExp("(^|\\s)(" + c + ")", "gi"), g = new RegExp("<(/*)(" + c + ")", "gi"), h = new RegExp("(^|[^\\n]*?\\s)(" + c + ")([^\\n]*)({[\\n\\w\\W]*?})", "gi"), i = b.createDocumentFragment(), j = b.documentElement, k = j.firstChild, l = b.createElement("body"), m = b.createElement("style"), n; o(b), o(i), k.insertBefore(m, k.firstChild), m.media = "print", a.attachEvent("onbeforeprint", function() { var a = -1, c = p(b.styleSheets, "all"), k = [], o; n = n || b.body; while ((o = h.exec(c)) != null) k.push((o[1] + o[2] + o[3]).replace(f, "$1.iepp_$2") + o[4]); m.styleSheet.cssText = k.join("\n"); while (++a < e) { var q = b.getElementsByTagName(d[a]), r = q.length, s = -1; while (++s < r) q[s].className.indexOf("iepp_") < 0 && (q[s].className += " iepp_" + d[a]) } i.appendChild(n), j.appendChild(l), l.className = n.className, l.innerHTML = n.innerHTML.replace(g, "<$1font") }), a.attachEvent("onafterprint", function() { l.innerHTML = "", j.removeChild(l), j.appendChild(n), m.styleSheet.cssText = "" }) } (a, b), e._enableHTML5 = f, e._version = d, g.className = g.className.replace(/\bno-js\b/, "") + " js " + u.join(" "); return e } (this, this.document)
// END Modernizr

//************************************************************************
// JS Animation
//************************************************************************
/*!
jsAnim: Powerful javascript animation
--------------------------------------------
Copyright 2009 Kevin Dolan
-http://www.thekevindolan.com
	
Code licensed under the MIT license
-See license.txt
	
v0.2
*/

//These vars are used to hold all jsAnimManagers
var jsAnimManagers = new Array();
var jsAnimManagerId = 0;

/*! public, accessible
jsAnimManager object constructor
Used by end-user to manage jsAnim objects
Params:
-[timestep] : time between frames, defaults to 40
*/
function jsAnimManager(timestep) {

    jsAnimManagers[jsAnimManagerId] = this;
    this.myId = jsAnimManagerId;
    jsAnimManagerId++;

    if (timestep)
        this.timestep = timestep;
    else
        this.timestep = 40;

    this.paused = false;

    this.animObjects = new Array();
    this.index = 0;

    //Used internally to process a single frame of all active animations
    this.step = function() {
        if (!this.paused) {
            for (x in this.animObjects) {
                this.animObjects[x].step();
            }
            setTimeout("jsAnimManagers[" + this.myId + "].step()", this.timestep);
        }
    };

    //Used internally to kill a jsAnimObject
    this.kill = function(id) {
        delete this.animObjects[id];
    };

    /*! public
    Called to create a new animation object
    Params:
    -objId : id of object being controlled
    */
    this.createAnimObject = function(objId) {
        var el = document.getElementById(objId);
        var id = this.index;
        this.animObjects[id] = new jsAnimObject(el, id, this);
        this.index++;
        return this.animObjects[id];
    };

    /*! public
    Called to pause the animation manager
    */
    this.pause = function() {
        this.paused = true;
    };

    /*! public
    Called to unpause the animation manager
    */
    this.resume = function() {
        this.paused = false;
        this.step();
    };

    /*! public
    Called to set the appropriate style values to allow position to be controlled by jsAnim
    Params:
    -objId : id of object to be registered
    -[fixed] : fixed positioning, false to absolute fixed, defaults to false
    */
    this.registerPosition = function(objId, fixed) {
        var el = document.getElementById(objId);
        var width = el.offsetWidth;
        var height = el.offsetHeight;

        if (fixed)
            el.style.position = "fixed";
        else
            el.style.position = "absolute";

        el.style.top = "0px";
        el.style.left = "50%";
        el.halfWidth = Math.floor(width / 2);
        el.halfHeight = Math.floor(height / 2);
        el.style.marginLeft = (-el.halfWidth) + "px";
        el.style.marginTop = (-el.halfHeight) + "px";

        el.positionRegistered = true;

        /*! public
        Called to manually set the position of this object
        */
        el.setPosition = function(x, y) {
            this.style.marginLeft = (x - this.halfWidth) + "px";
            this.style.marginTop = (y - this.halfHeight) + "px";
        };

    };

    this.step();
    return true;
}

/*! accesible
jsAnimObject object constructor
Used internally to hold the state of a single animation manager
Params:
-obj : object being animated
		
*/
function jsAnimObject(obj, id, manager) {

    this.id = id;
    this.obj = obj;
    this.paused = false;
    this.animEntries = new Array();
    this.animLoops = new Array();
    this.current = 0;
    this.manager = manager;

    this.step = function() {
        if (!this.paused) {
            //Ugly code to get only the first element in the array
            for (x in this.animEntries) {
                var finished = this.animEntries[x].step();
                if (finished) {
                    this.animLoops[x]--;
                    this.animEntries[x].current = 0;
                    this.animEntries[x].onLoop();
                }
                if (this.animLoops[x] == 0) {
                    this.animEntries[x].onComplete();
                    delete this.animEntries[x];
                }
                break;
            }
        }
    };

    /*! public
    Called to add an animation to the chain
    Params:
    -params : a collection in the containing the following elements
    - property : the Prop object to animate
    - [from] : optional from value, if unspecified current value is used
    - to : the value to animate to
    - duration : the length of time this animation should take
    - [ease] : the jsAnimEase object to use, if unspecified linear will be used
    - [loop] : the number of times to loop the animation, negative values are infinite, if unspecified 1 will be used
    - [onLoop] : the callback function for loop completion
    - [onComplete] : the callback function for animation completion
    */
    this.add = function(params) {

        var property = params.property;
        var from = params.from
        var to = params.to;
        var duration = params.duration;
        if (params.ease)
            var ease = params.ease;
        else
            var ease = jsAnimEase.linear;
        if (params.loop)
            var loop = params.loop;
        else
            var loop = 1;
        if (params.onLoop)
            var onLoop = params.onLoop;
        else
            var onLoop = function() { };
        if (params.onComplete)
            var onComplete = params.onComplete;
        else
            var onComplete = function() { };

        this.animEntries[this.current] = new jsAnimEntry(this.obj, property, from, to, duration, this.manager.timestep, ease, onLoop, onComplete);
        this.animLoops[this.current] = loop;

        this.current++;

    };

    /*! public
    Called to skip the current animation, can be used to exit an infinite loop
    */
    this.skip = function() {
        //Ugly code to get only the first element in the array
        for (x in this.animEntries) {
            delete this.animEntries[x];
            break;
        }
    };

    /*! public
    Called to pause this animator
    */
    this.pause = function() {
        this.paused = true;
    };

    /*! public
    Called to resum this animator
    */
    this.resume = function() {
        this.paused = false;
    };

    /*! public
    Called to kill this animator
    */
    this.kill = function() {
        this.manager.kill(this.id);
    };

    return true;
}

/*! public, accesible
Pos object constructor
Called to store an x and y coordinate representing an object's center
according to the jsAnim coordinate system
Params:
-x : x coordinate, 0 is center, negative is left, positive is right
-y : y coordinate, 0 is top, positive id below
*/
function Pos(x, y) {

    //public
    this.x = x;

    //public
    this.y = y;

    return true;
}

/*! public, accesible
Dim object constructor
Called to store a width/height dimension
Params:
-w : width
-h : height
*/
function Dim(w, h) {

    //public
    this.w = w;

    //public
    this.h = h;

    return true;
}

/*! public, accesible
Col object constructor
Called to store an RGB color
Params:
-r : red value (0,255)
-g : green value (0,255)
-b : blue value (0,255)
*/
function Col(r, g, b) {

    //public
    this.r = r;

    //public
    this.g = g;

    //public
    this.b = b;

    return true;
}

/*! 
jsAnimEntry object constructor
Used internally to hold the state of single animation entry
Params:
-property : jsAnimProp object
-from : initial value
-to : end value
-duration : total time of animation (ms)
-ease : jsAnimEase object
-timestep : the timestep value of the animation manager
-onLoop : called after each loop
-onComplete : called after completion
*/
function jsAnimEntry(obj, property, from, to, duration, timestep, ease, onLoop, onComplete) {

    this.obj = obj;
    this.property = property;
    this.from = from;
    this.to = to;
    this.duration = duration;
    this.timestep = timestep;
    this.ease = ease;
    this.current = 0;
    this.onLoop = onLoop;
    this.onComplete = onComplete;

    /*!
    Used internally to move the object one step
    Returns : true if this anim entry has completed, false otherwise
    */
    this.step = function() {
        if (!this.from)
            this.from = this.property.current(this.obj);

        if (this.current >= this.duration) {
            var p = this.ease.transform(1);
            this.property.update(this.obj, this.from, this.to, p);
            return true;
        }
        else {
            var t = this.current / this.duration;
            var p = this.ease.transform(t);
            this.property.update(this.obj, this.from, this.to, p);
            this.current += this.timestep;
            return false;
        }
    };

    return true;
}

/*! public
jsAnimEase objects
Used to control easing
Methods:
transform : Transform a number 0-1 representing a time proportion
to a new number 0-1 representing a progress proportion 
*/
var jsAnimEase = {

    /*!public
    Constant Rate
    */
    linear: {
        transform: function(t) {
            return t;
        }
    },

    /*!public
    Starts slow, then speeds up
    */
    parabolicPos: {
        transform: function(t) {
            return t * t;
        }
    },

    /*!public
    Starts fast, then slows down
    */
    parabolicNeg: {
        transform: function(t) {
            return 1 - (t - 1) * (t - 1);
        }
    },

    /*!public
    Overshoots target then returns to target
    Params:
    -g : overshoot amount [0-1]
    */
    backout: function(g) {
        return {
            transform: function(t) {
                return (-1 * t * (t + g - 2)) / (1 - g);
            }
        };
    },

    /*!public
    Backs up a bit then moves to target
    Params:
    -g : backup amount [0-1]
    */
    backin: function(g) {
        return {
            transform: function(t) {
                return 1 + ((t + 1 - g) * ((t + 1 - g) + g - 2)) / (1 - g);
            }
        };
    },

    /*!public
    Goes to target and then back at constant rate
    */
    bounceLinear: {
        transform: function(t) {
            if (t < 0.5)
                return 2 * t;
            else
                return 1 - 2 * (t - 0.5)
        }
    },

    /*!public
    Goes to target and then back at variable rate
    */
    bounceParabolic: {
        transform: function(t) {
            return -4 * t * (t - 1);
        }
    },

    /*!public
    Goes to target and then back smoothly
    */
    bounceSmooth: {
        transform: function(t) {
            return 0.5 - 0.5 * Math.cos(2 * Math.PI * t);
        }
    }
}

/*!
Utility objects for internal use
*/
var jsAnimUtil = {

    interp: function(v1, v2, percent) {
        if (isNaN(v1))
            v1 = 0;
        if (isNaN(v2))
            v2 = 0;
        var v = v1 + percent * (v2 - v1);
        return Math.floor(v);
    },

    getCSS: function(elem, field) {
        var css = document.defaultView && document.defaultView.getComputedStyle ?
			document.defaultView.getComputedStyle(elem, null)
			: elem.currentStyle || elem.style;
        return css[field];
    },

    explode: function(delimiter, string, limit) {
        // http://kevin.vanzonneveld.net
        // +     original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
        // +     improved by: kenneth
        // +     improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
        // +     improved by: d3x
        // +     bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
        // *     example 1: explode(' ', 'Kevin van Zonneveld');
        // *     returns 1: {0: 'Kevin', 1: 'van', 2: 'Zonneveld'}
        // *     example 2: explode('=', 'a=bc=d', 2);
        // *     returns 2: ['a', 'bc=d']

        var emptyArray = { 0: '' };

        // third argument is not required
        if (arguments.length < 2 ||
			typeof arguments[0] == 'undefined' ||
			typeof arguments[1] == 'undefined') {
            return null;
        }

        if (delimiter === '' ||
			delimiter === false ||
			delimiter === null) {
            return false;
        }

        if (typeof delimiter == 'function' ||
			typeof delimiter == 'object' ||
			typeof string == 'function' ||
			typeof string == 'object') {
            return emptyArray;
        }

        if (delimiter === true) {
            delimiter = '1';
        }

        if (!limit) {
            return string.toString().split(delimiter.toString());
        } else {
            // support for limit argument
            var splitted = string.toString().split(delimiter.toString());
            var partA = splitted.splice(0, limit - 1);
            var partB = splitted.join(delimiter.toString());
            partA.push(partB);
            return partA;
        }
    }
}

/*! public
Prop objects
Used to keep track of which property is being controlled
Methods:
update : update the property to where it should be at the given time
current : return a natural representation of the current property
*/
var Prop = {
    /*! public
    Wait, while doing no animating
    */
    wait: {
        update: function(obj, from, to, percent) { },
        current: function(obj) { return 0; }
    },

    /*! public
    Follows a linear path
    */
    position: {
        update: function(obj, from, to, percent) {
            var x = jsAnimUtil.interp(from.x, to.x, percent);
            var y = jsAnimUtil.interp(from.y, to.y, percent);

            obj.setPosition(x, y);
        },

        current: function(obj) {
            var left = parseInt(obj.style.marginLeft);
            var top = parseInt(obj.style.marginTop);
            var x = left + obj.halfWidth;
            var y = top + obj.halfHeight;
            return new Pos(x, y);
        }
    },

    /*! public
    Follows a semicircular path
    Params:
    -clockwise : True for clockwise, false otherwise
    */
    positionSemicircle: function(clockwise) {
        return {
            update: function(obj, from, to, percent) {
                var centerX = (from.x + to.x) / 2;
                var centerY = (from.y + to.y) / 2;

                var h = centerY - from.y;
                var w = from.x - centerX;

                var dist = Math.sqrt(h * h + w * w);

                if (w == 0) {
                    if (h > 0)
                        var initAngle = -Math.PI / 2;
                    else
                        var initAngle = Math.PI / 2;
                }
                else {
                    var atan = Math.atan(h / Math.abs(w));
                    if (w > 0)
                        var initAngle = atan;
                    else {
                        var initAngle = Math.PI - atan;
                    }
                }

                if (clockwise)
                    var addAngle = -percent * Math.PI;
                else
                    var addAngle = percent * Math.PI;

                var angle = initAngle + addAngle;

                var x = Math.floor(centerX + dist * Math.cos(angle));
                var y = Math.floor(centerY - dist * Math.sin(angle));

                obj.setPosition(x, y);
            },

            current: function(obj) {
                var left = parseInt(obj.style.marginLeft);
                var top = parseInt(obj.style.marginTop);
                var x = left + obj.halfWidth;
                var y = top + obj.halfHeight;
                return new Pos(x, y);
            }
        }
    },

    /*! public
    Follows a circular path through target then back to start
    Params:
    -clockwise : True for clockwise, false otherwise
    */
    positionCircle: function(clockwise) {
        return {
            update: function(obj, from, to, percent) {
                var centerX = (from.x + to.x) / 2;
                var centerY = (from.y + to.y) / 2;

                var h = centerY - from.y;
                var w = from.x - centerX;

                var dist = Math.sqrt(h * h + w * w);

                if (w == 0) {
                    if (h > 0)
                        var initAngle = -Math.PI / 2;
                    else
                        var initAngle = Math.PI / 2;
                }
                else {
                    var atan = Math.atan(h / Math.abs(w));
                    if (w > 0)
                        var initAngle = atan;
                    else {
                        var initAngle = Math.PI - atan;
                    }
                }

                if (clockwise)
                    var addAngle = 2 * percent * Math.PI;
                else
                    var addAngle = -2 * percent * Math.PI;

                var angle = initAngle + addAngle;

                var x = Math.floor(centerX + dist * Math.cos(angle));
                var y = Math.floor(centerY + dist * Math.sin(angle));

                obj.setPosition(x, y);
            },

            current: function(obj) {
                var left = parseInt(obj.style.marginLeft);
                var top = parseInt(obj.style.marginTop);
                var x = left + obj.halfWidth;
                var y = top + obj.halfHeight;
                return new Pos(x, y);
            }
        }
    },

    //public
    top: {
        update: function(obj, from, to, percent) {
            obj.style.top = jsAnimUtil.interp(from, to, percent) + "px";
        },

        current: function(obj) {
            return parseInt(jsAnimUtil.getCSS(obj, 'top'));
        }

    },

    //public
    right: {
        update: function(obj, from, to, percent) {
            obj.style.right = jsAnimUtil.interp(from, to, percent) + "px";
        },

        current: function(obj) {
            return parseInt(jsAnimUtil.getCSS(obj, 'right'));
        }
    },

    //public
    bottom: {
        update: function(obj, from, to, percent) {
            obj.style.bottom = jsAnimUtil.interp(from, to, percent) + "px";
        },

        current: function(obj) {
            return parseInt(jsAnimUtil.getCSS(obj, 'bottom'));
        }
    },

    //public
    left: {
        update: function(obj, from, to, percent) {
            obj.style.left = jsAnimUtil.interp(from, to, percent) + "px";
        },

        current: function(obj) {
            return parseInt(jsAnimUtil.getCSS(obj, 'left'));
        }
    },

    //public
    margin: {
        update: function(obj, from, to, percent) {
            obj.style.margin = jsAnimUtil.interp(from, to, percent) + "px";
        },

        current: function(obj) {
            return parseInt(jsAnimUtil.getCSS(obj, 'margin'));
        }
    },

    //public
    marginTop: {
        update: function(obj, from, to, percent) {
            obj.style.marginTop = jsAnimUtil.interp(from, to, percent) + "px";
        },

        current: function(obj) {
            return parseInt(jsAnimUtil.getCSS(obj, 'marginTop'));
        }
    },

    //public
    marginRight: {
        update: function(obj, from, to, percent) {
            obj.style.marginRight = jsAnimUtil.interp(from, to, percent) + "px";
        },

        current: function(obj) {
            return parseInt(jsAnimUtil.getCSS(obj, 'marginRight'));
        }
    },

    //public
    marginBottom: {
        update: function(obj, from, to, percent) {
            obj.style.marginBottom = jsAnimUtil.interp(from, to, percent) + "px";
        },

        current: function(obj) {
            return parseInt(jsAnimUtil.getCSS(obj, 'marginBottom'));
        }
    },

    //public
    marginLeft: {
        update: function(obj, from, to, percent) {
            obj.style.marginLeft = jsAnimUtil.interp(from, to, percent) + "px";
        },

        current: function(obj) {
            return parseInt(jsAnimUtil.getCSS(obj, 'marginLeft'));
        }
    },

    //public
    padding: {
        update: function(obj, from, to, percent) {
            obj.style.padding = jsAnimUtil.interp(from, to, percent) + "px";
        },

        current: function(obj) {
            return parseInt(jsAnimUtil.getCSS(obj, 'padding'));
        }
    },

    //public
    paddingTop: {
        update: function(obj, from, to, percent) {
            obj.style.paddingTop = jsAnimUtil.interp(from, to, percent) + "px";
        },

        current: function(obj) {
            return parseInt(jsAnimUtil.getCSS(obj, 'paddingTop'));
        }
    },

    //public
    paddingRight: {
        update: function(obj, from, to, percent) {
            obj.style.paddingRight = jsAnimUtil.interp(from, to, percent) + "px";
        },

        current: function(obj) {
            return parseInt(jsAnimUtil.getCSS(obj, 'paddingRight'));
        }
    },

    //public
    paddingBottom: {
        update: function(obj, from, to, percent) {
            obj.style.paddingBottom = jsAnimUtil.interp(from, to, percent) + "px";
        },

        current: function(obj) {
            return parseInt(jsAnimUtil.getCSS(obj, 'paddingBottom'));
        }
    },

    //public
    paddingLeft: {
        update: function(obj, from, to, percent) {
            obj.style.paddingLeft = jsAnimUtil.interp(from, to, percent) + "px";
        },

        current: function(obj) {
            return parseInt(jsAnimUtil.getCSS(obj, 'paddingLeft'));
        }
    },

    //public
    borderWidth: {
        update: function(obj, from, to, percent) {
            obj.style.borderWidth = jsAnimUtil.interp(from, to, percent) + "px";
        },

        current: function(obj) {
            return parseInt(jsAnimUtil.getCSS(obj, 'borderWidth'));
        }
    },

    //public
    borderTopWidth: {
        update: function(obj, from, to, percent) {
            obj.style.borderTopWidth = jsAnimUtil.interp(from, to, percent) + "px";
        },

        current: function(obj) {
            return parseInt(jsAnimUtil.getCSS(obj, 'borderTopWidth'));
        }
    },

    //public
    borderRightWidth: {
        update: function(obj, from, to, percent) {
            obj.style.borderRightWidth = jsAnimUtil.interp(from, to, percent) + "px";
        },

        current: function(obj) {
            return parseInt(jsAnimUtil.getCSS(obj, 'borderRightWidth'));
        }
    },

    //public
    borderBottomWidth: {
        update: function(obj, from, to, percent) {
            obj.style.borderBottomWidth = jsAnimUtil.interp(from, to, percent) + "px";
        },

        current: function(obj) {
            return parseInt(jsAnimUtil.getCSS(obj, 'borderBottomWidth'));
        }
    },

    //public
    borderLeftWidth: {
        update: function(obj, from, to, percent) {
            obj.style.borderLeftWidth = jsAnimUtil.interp(from, to, percent) + "px";
        },

        current: function(obj) {
            return parseInt(jsAnimUtil.getCSS(obj, 'borderLeftWidth'));
        }
    },

    //public
    fontSize: {
        update: function(obj, from, to, percent) {
            obj.style.fontSize = jsAnimUtil.interp(from, to, percent) + "pt";
        },

        current: function(obj) {
            return parseInt(jsAnimUtil.getCSS(obj, 'fontSize'));
        }
    },

    //public
    height: {
        update: function(obj, from, to, percent) {
            var v = jsAnimUtil.interp(from, to, percent);

            obj.style.height = v + "px";

            //Update the position if registered
            if (obj.positionRegistered) {
                var y = parseInt(obj.style.marginTop) + obj.halfHeight;
                obj.halfHeight = Math.floor(obj.offsetHeight / 2);
                obj.style.marginTop = y - obj.halfHeight + "px";
            }
        },

        current: function(obj) {
            var ht = jsAnimUtil.getCSS(obj, 'height');
            if (ht == "auto")
                return obj.offsetHeight;
            else
                return parseInt(ht);
        }
    },

    //public
    width: {
        update: function(obj, from, to, percent) {
            var v = jsAnimUtil.interp(from, to, percent);

            obj.style.width = v + "px";

            //Update the position if registered
            if (obj.positionRegistered) {
                var x = parseInt(obj.style.marginLeft) + obj.halfWidth;
                obj.halfWidth = Math.floor(obj.offsetWidth / 2);
                obj.style.marginLeft = x - obj.halfWidth + "px";
            }
        },

        current: function(obj) {
            return parseInt(jsAnimUtil.getCSS(obj, 'width'));
        }
    },

    //public
    dimension: {
        update: function(obj, from, to, percent) {
            var h = jsAnimUtil.interp(from.h, to.h, percent);
            var w = jsAnimUtil.interp(from.w, to.w, percent);

            obj.style.height = h + "px";
            obj.style.width = w + "px";

            //Update the position if registered
            if (obj.positionRegistered) {
                var y = parseInt(obj.style.marginTop) + obj.halfHeight;
                obj.halfHeight = Math.floor(obj.offsetHeight / 2);
                obj.style.marginTop = (y - obj.halfHeight) + "px";

                var x = parseInt(obj.style.marginLeft) + obj.halfWidth;
                obj.halfWidth = Math.floor(obj.offsetWidth / 2);
                obj.style.marginLeft = (x - obj.halfWidth) + "px";
            }
        },

        current: function(obj) {
            var ht = jsAnimUtil.getCSS(obj, 'height');
            if (ht == "auto")
                var h = obj.offsetHeight;
            else
                var h = parseInt(ht);
            var w = parseInt(jsAnimUtil.getCSS(obj, 'width'));
            return new Dim(w, h);
        }
    },

    //public
    color: {
        update: function(obj, from, to, percent) {
            r = jsAnimUtil.interp(from.r, to.r, percent);
            g = jsAnimUtil.interp(from.g, to.g, percent);
            b = jsAnimUtil.interp(from.b, to.b, percent);

            obj.style.color = "rgb(" + r + "," + g + "," + b + ")";
        },

        current: function(obj) {
            var color = jsAnimUtil.getCSS(obj, 'color');
            color = color.substring(4, color.length - 1);
            var rgb = jsAnimUtil.explode(",", color);
            return new Col(parseInt(rgb[0]), parseInt(rgb[1]), parseInt(rgb[2]));
        }
    },

    //public
    backgroundColor: {
        update: function(obj, from, to, percent) {
            r = jsAnimUtil.interp(from.r, to.r, percent);
            g = jsAnimUtil.interp(from.g, to.g, percent);
            b = jsAnimUtil.interp(from.b, to.b, percent);

            obj.style.backgroundColor = "rgb(" + r + "," + g + "," + b + ")";
        },

        current: function(obj) {
            var color = jsAnimUtil.getCSS(obj, 'backgroundColor');
            color = color.substring(4, color.length - 1);
            var rgb = jsAnimUtil.explode(",", color);

            return new Col(parseInt(rgb[0]), parseInt(rgb[1]), parseInt(rgb[2]));
        }
    },

    //public
    borderColor: {
        update: function(obj, from, to, percent) {
            r = jsAnimUtil.interp(from.r, to.r, percent);
            g = jsAnimUtil.interp(from.g, to.g, percent);
            b = jsAnimUtil.interp(from.b, to.b, percent);

            obj.style.borderColor = "rgb(" + r + "," + g + "," + b + ")";
        },

        current: function(obj) {
            var color = jsAnimUtil.getCSS(obj, 'borderColor');
            color = color.substring(4, color.length - 1);
            var rgb = jsAnimUtil.explode(",", color);
            return new Col(parseInt(rgb[0]), parseInt(rgb[1]), parseInt(rgb[2]));
        }
    },

    //public
    opacity: {
        update: function(obj, from, to, percent) {
            v = jsAnimUtil.interp(100 * from, 100 * to, percent);
            obj.style.opacity = v / 100;
        },

        current: function(obj) {
            return jsAnimUtil.getCSS(obj, 'opacity');
        }
    }
}
//************************************************************************
// END - JS Animation
//************************************************************************
