$(document).ready(function() {

    // FF renders cleartype text weirdly with opacity, so turn it off
    /*
    if ($.browser.mozilla || ($.browser.msie && parseInt(jQuery.browser.version) <= 6)) {
        $(".baker-nav").css({
            "opacity" : "1", 
            "filter" : "alpha(opacity=100)"
        });
    }
    */

    $(".baker-nav").bgiframe();

    // Top nav
    $("a.baker-nav-has-dropdown").click(function() {
        var index = $("a.baker-nav-has-dropdown").index(this);
        if (!$(".baker-nav").eq(index).hasClass("active")) {
            showNav(index);
        } else {
            hideNav();
        }
        return false;
    });
    $(document).click(function(e) {
        if (!$(e.target).is(".baker-nav") && $(e.target).parents(".baker-nav").size() == 0) {
            hideNav();
        }
    });
    function showNav(index) {
        //$("#baker-navigation a.has-dropdown").removeClass("active");
        //$("#baker-navigation a.has-dropdown").eq(index).addClass("active");
        //$(".baker-nav").removeClass("active");
        //$(".baker-nav").eq(index).addClass("active");
        $(".baker-nav").removeClass("active");
        $(".baker-nav").eq(index).addClass("active");
    }
    function hideNav() {
        //$("#baker-navigation a.has-dropdown").removeClass("active");
        $(".baker-nav").removeClass("active");
    }

    // Browse products nav
    $("#baker-nav-browse-left li a.has-subnav").click(function() {
        var index = $("#baker-nav-browse-left li a.has-subnav").index(this);
        $("#baker-nav-browse-left li a.has-subnav").removeClass("highlight");
        $("#baker-nav-browse-left li a.has-subnav").eq(index).addClass("highlight");
        $(".baker-nav-browse-subnav").removeClass("active");
        $(".baker-nav-browse-subnav").eq(index).addClass("active");
        if (index != 0) {
            $("#baker-nav-browse-bottom").css("display", "none");
        } else {
            $("#baker-nav-browse-bottom").css("display", "block");
        }
        return false;
    });

    // search box
    var myInterval;
    function waitForAutocompleteContent() {
        if ($('#autocomplete div').size() > 0) {
            $('.yui-skin-sam').css('visibility', 'visible');
            clearInterval(myInterval);
        }
    }
    $(function() {
        myInterval = setInterval('waitForAutocompleteContent()', 10);
    });

    var initialSearchText = $("#q.searchbox").val();
    $("#q.searchbox").focus(function() {
        $(this).parents("form").siblings(".search-icon").css("display", "none");
    }).blur(function() {
        if ($(this).val().length == 0) {
            $(this).parents("form").siblings(".search-icon").css("display", "block");
        }
    });

    $(".finish-close-window").click(function() {
        $(".finish-outer-div").css("display","none");
    });
    $(".designer-palette").click(function() {
        $(".finish-outer-div").css("display","block");
    });


});

function launchRoomPlanner(){
	newWindow=window.open('http://roomplanner.icovia.com/Baker/resources/icovia.aspx' ,'icovia','height=550,width=800,top='+((screen.height/2)-(300))+',left='+((screen.width/2)-(400))+',status=no,toolbar=no,scrollbars=no,resizable=yes,menubar=no'); void(0);
	var popUpMsg = 'You appear to have a pop-up blocker that prevents the Room Planner from opening. Please enable pop-ups for this site and try again. Thank you.'; 
	if(!newWindow){ 
		alert(popUpMsg); 
	}  
}

function launchAdCampaign(){
	newWindow=window.open('/baker/ad_campaign/gallery.html' ,'adcampaign','height=611,width=800,top='+((screen.height/2)-(300))+',left='+((screen.width/2)-(400))+',status=no,toolbar=no,scrollbars=no,resizable=yes,menubar=no'); void(0);
	var popUpMsg = 'You appear to have a pop-up blocker that prevents the Ad Campaign window from opening. Please enable pop-ups for this site and try again. Thank you.'; 
	if(!newWindow){ 
		alert(popUpMsg); 
	}  
}


function openSlideShow(url) {
	window.open(url,'','width=620,height=540');
	return false;
}

function openBrightcoveWindow(brightcoveUrl) {
    var url = "http://link.brightcove.com/services/link/bcpid1078541307/bclid1078597801/bctid1109919432";
    if (brightcoveUrl) {
        url = brightcoveUrl;
    }
    window.open(url, 'videolibrary', 'width=1000,height=660,resizable=yes');
}



