jQuery.noConflict(); // Use jQuery to avoid Prototype library conflict in Sitecore
// NB: noConflict seems to throw IE6 into a spin with undefined errors

jQuery(document).ready(function($){

    // use iframe state selector if javascript is enabled
    $('.entry').each(function() {
        var url = $(this).attr("href");

        $(this).attr("href", url.replace("&es=disable",""));
        
    });

    if ($('#mainFeature').attr("id") == "mainFeature") {        
        var flashVersion = "0,0,0";
        var flashAvailable = false;
        try
        {
            var Plugin = navigator.plugins['Shockwave Flash'] || ActiveXObject;
            flashVersion = Plugin.description || (function () {
				try {
					return (new Plugin('ShockwaveFlash.ShockwaveFlash')).GetVariable('$version');
				}
				catch (eIE) {}
			}());
			
			if (flashVersion == undefined)
			{
			    "0,0,0";
			}
			
			flashVersion = flashVersion.match(/^[A-Za-z\s]*?(\d+)[\.|,](\d+)(?:\s+[d|r]|,)(\d+)/);
			
			flashAvailable = flashVersion != undefined && flashVersion[1] > 0 ? true : false;
        }
        catch(e)
        {
            flashAvailable = false;
        }        
        
        if (flashAvailable == true) {
            $("._feature").each(function(i) {
                if ($(this).find("embed").size() > 0) {
                    $(this).find("a").remove();
                }
            })
        }
        else {
            $("._feature").each(function(i) {
                if ($(this).find("img").length == 0) {
                    $(this).remove();
                } else {                        
                    $(this).find("embed").remove();                        
                }
            });
        }  
    }

    // toggle
    //Hide (Collapse) the toggle containers on load
    $(".sitemap .toggle_container").hide();

    //Switch the "Open" and "Close" state per click
    $(".trigger").click(function() {
        if($(this).hasClass('active')){
            $(this).removeClass("active");
            return false;
        }else{
            $(this).addClass("active");
            return false;
        }
    });

    //Slide up and down on click
    $(".trigger").click(function() {
        $(this).next(".toggle_container").slideToggle("slow,");
    });

    Shadowbox.init();

    var timing = parseInt($("#timing").attr("value"));

    if ($('#mainFeature').attr("id") == "mainFeature") {
        $('#mainFeature').cycle({
            fx: 'fade',
            pager: '#paginationWrapper',
            timeout: timing
        });
        $('.date-pick').datePicker();
    }


    //var dropdown = $('.dropdown .box').eq(0);
    //var height = $(dropdown).find('.wrap > ul').height()
    //$(dropdown).find('.wrap').css('height',height+20+"px")
    //$(dropdown).css('height',height+30+"px")
});

