var siteroot = (typeof(fullsiteroot) == "function") && (typeof(sitehost) == "function") ? fullsiteroot().replace(sitehost(), "") : "/";

document.observe("dom:loaded", function(){
    init();
    /*if ($("checklist")) {
        setChecklist();
    }*/
    //create wishlist meter
    if (typeof(wishlistBar) != "undefined" && $$(".enable_bar")[0]) {
        createMeter(wishlistBar);
    }
});



var init = function(){
    $("search").writeAttribute("value", "Search Catalog");
    resetField("search");
	
    $$('ul.hlist li:first-child').each(function(element, index){
        element.setStyle({
            borderLeft: "0px"
        });
    });
    
	$$(".checklistnav li a").each(function(e){
        e.observe("click", function(ev){
			Event.stop(ev);
            $(e).up("ul").select("a").invoke("removeClassName", "selected");
            $("calendar").setStyle({
                display: "none"
            });
            $("checklist").setStyle({
                display: "none"
            });
            var open = e.getAttribute("href", 2);
            $$(open)[0].setStyle({
                display: "block"
            });
            e.addClassName("selected");
            
        });
    });
    if ($("calendarhtml")) {
        var header = $$("#calendar #calendarhtml th");
        header[header.length - 1].setStyle({
            borderRight: "0px"
        });
        header[header.length - 1].setStyle({
            width: "87px"
        });
    }
    
    
    delete init;
};

var resetField = function(field){
    $(field).observe('click', function(){
        $(field).writeAttribute("value", "");
        $(field).setStyle({
            color: '#666'
        });
    });
}

var setChecklist = function(){
    $$("#checklist table tr:nth-child(odd)").each(function(element, index){
        element.addClassName("odd");
    });
    if ($("checklist")) {
        $$("#checklist .activity a").each(function(e, index){
            e.observe('click', function(){
            
                //calls to flash
				var text = e.innerHTML.stripTags();
                callFlash(text);
                
                var completed = $$(".completed tr");
                completed[completed.length - 1].insert({
                    after: e.up(2)
                });
                $$("#checklist table tr:nth-child(even)").each(function(el){
                    el.removeClassName("odd");
                });
                $$("#checklist table tr:nth-child(odd)").each(function(el){
                    el.addClassName("odd");
                });
                return false;
            });
        });
    }
    delete setChecklist;
}

var callFlash = function(text){
	var myFlashMovie = $("flashmovie");
	//myFlashMovie.display(text);
}

//fixing IE6 draw bug - the following line forcefully redraws an element that IE simply refuses to draw otherwise
//@cc_on new function() {var hack = setInterval(function() {if ($("infographics_link")) $("infographics_link").style.border="0"},100); setTimeout(function() {clearInterval(hack)}, 10000)}()
