/* superceded by a central mitsulib file
var vehicleCommon = {
    init : function(){
        // this check ensures multiple shades are not created
        var exist = document.getElementById("shade");
        if(!exist){
            vehicleCommon.shadeBuild();
        }
    },
    shadeBuild : function(){
        // this check ensures multiple shades are not created
        var exist = document.getElementById("shade");
        if(!exist){
            var shade = "<div id='shade' style='"
            shade += (IE6 == true || IE7 == true) ? "filter:alpha(opacity=70);" : "opacity:0.7;";
            shade += " background:#000000; z-index: 9001; display:none; position:absolute; top:0px; left:0px; width:100%; height:" + $(document).height() + "px'></div>"
            $("body").append(shade);
            $("#shade").click(function(){
                vehicleCommon.shadeHide();
            });
        }
    },
    // utlities that can be called to hide and show the shade
    shadeShow : function(){
        $("#shade").fadeIn();
    },
    // utlities that can be called to hide and show the shade
    shadeHide : function(){
        $("#shade").fadeOut();
    },
    // used to make the page scroll to a certain point
    scrollTo : function(id){
        $('html, body').animate({ scrollTop : $(id).offset().top + "px" }, 750);
    },
    // used to scroll to top before changing page 
    // no real reason this can't be applied to all links
    // but it will HAVE to be activated AFTER everything else, since some links are disabled
    scrollPageLoad : function(url){
        $('html, body').animate({ scrollTop : $("body").offset().top + "px" }, 500, function(){
            location.href = url;
        });
    }
};*/

var top360 = {
    init : function(){
        vehicleCommon.init();
        var check = document.getElementById("top360");
        if(check){
            var $top360 = $("#top360");
            var id = $top360[0].href.split("#")[1];
            $top360.click(function(){
                top360.show360(id);
                return false;
            }).fadeIn();
            $("#shade").click(function(){
                top360.hide360(id);
                return false;
            });
            $("#top360close").click(function(){
                top360.hide360(id);
                return false;
            });
        }
    },
    show360 : function(id){
        $("#"+id).fadeIn();
        vehicleCommon.shadeShow();
    },
    hide360 : function(id){
        $("#"+id).fadeOut();
        vehicleCommon.shadeHide();
    }
};

var vehicleNav = {
    init : function(){
        // interally global variables
        $vehicleCTA = $("#vehicleCTA");
        $vehicleCTAToggle = $("#vehicleCTAToggle")
        // --
        $vehicleCTAToggle.click(function(){
            if($vehicleCTA[0].style.top == "0px"){
                $vehicleCTA.animate({ "top" : "-36px" });
                $vehicleCTAToggle[0].style.backgroundImage = "url('/images/vehicle/nav/nav-cta-hide.gif')";
                $vehicleCTAToggle.find("span")[0].innerHTML = "Hide Brochure and Test Drive Buttons";
            }
            else{
                $vehicleCTA.animate({ "top" : "0px" });
                $vehicleCTAToggle[0].style.backgroundImage = "url('/images/vehicle/nav/nav-cta-show.gif')";
                $vehicleCTAToggle.find("span")[0].innerHTML = "Show Brochure and Test Drive Buttons";
            }
            return false;
        }).hover(function(){
            $vehicleCTAToggle.find("span").fadeIn();
        }, function(){
            $vehicleCTAToggle.find("span").fadeOut();
        });
    },
    toggleCTA : function(show){
        //show = (show) ? show : true;
        if(!show){
            $vehicleCTA.animate({ "top" : "0px" });
            $vehicleCTAToggle.fadeIn();
        }
        else{
            $vehicleCTA.animate({ "top" : "-36px" });
            $vehicleCTAToggle.fadeOut();
        }
    }
};


/* not used anymore as far as I can tell
var mspPage = {
    init : function(){
        $("#mspPrice th").hover(function(){ 
            $(this).find("span").fadeIn(); 
        }, function(){ 
            $(this).find("span").fadeOut(); 
        }).find("strong").css({
            "border-bottom" : "1px dotted #3a3a3a",
            "color" : "#4f4f4f"
        }).end().find("span").css({ 
            "display" : "none", 
            "position" : "absolute", 
            "top" : "90%", 
            "right" : "-5px", 
            "border" : "1px solid #9f9f9f", 
            "background-color" : "#ffffff",
            "width" : "100px"
        });
    }
};*/

var initPage = {
    init : function(){
        var url = window.location.href.split("/");
        var page = url[4].split(".aspx")[0].toLowerCase();
        var anima = false;
        var animb = false;
        if(url.length == 5){
            switch(url[4].split(".aspx")[0].toLowerCase()){
                case "test-drive":
                case "msp":
                case "motability":
                case "personas":
                case "the-future":
                case "electric-living":
                case "a-real-car":
                case "news":
                    //top360.init();
                    mitsulib.scrollTo("#headerImg");
                    break;
                default:
            }
        }
        if(page != "brochure"){
            var a = $($("#vehicleCTABrochure").find("img")[1])
            $("#vehicleCTABrochure").hover(function(){
                if(!anima){
                    anima = true;
                    a.fadeIn(500, function(){
                        anima = false;
                    });
                }
            }, function(){
                a.fadeOut();
            });
        }
        if(page != "test-drive"){
            var b = $($("#vehicleCTATestdrive").find("img")[1])
            $("#vehicleCTATestdrive").hover(function(){
                if(!animb){
                    animb = true;
                    b.fadeIn(500, function(){
                        animb = false;
                    });
                }
            }, function(){
                b.fadeOut();
            });
        }
    }
}

$(document).ready(function(){
    initPage.init();
});
