jQuery.fn.selectedItem = function() {
  return $(this).find('option:eq(' + $(this).attr('selectedIndex') + ')');
}

$(document).ready(function(){
    var initialOpt = $.query.get('slideshow');
    if (initialOpt) 
    {
        loadSlideshow(initialOpt);
        if (initialOpt == "slideshow_aww" || initialOpt == "slideshow_cookbook" || initialOpt == "slideshow_style") {
            selectSlideshowTab(document.getElementById(initialOpt));
        } else {
            clearSlideshowTab();
        }          
    }
});

function selectSlideshowOption(element) {
    clearSlideshowTab();
    element.className = "selected";
}

function clearSlideshowOption() {
    var tabLinks = document.getElementById("slideshowDropdownTop").getElementsByTagName("ul")[0].getElementsByTagName("li");
    for(var i=0; i<tabLinks.length; i++)
    {
	    tabLinks[i].className = "";
    }
}

function loadSlideshow(arg) {
    var isPreview = ($.query.get('mode') == 'preview');
    var call_url = "/slideshow_call.aspx?";
    if (isPreview) {
        call_url = call_url + 'mode=preview&sectionid=';
    }
    else {
        call_url = call_url + 'sectionid=';
    }
    
    if (arg == "slideshow_aww") 
    {	call_url = call_url + "9221";
    }
    else if (arg == "slideshow_pictures") 
    {	call_url = call_url + "9885&subsectionid=153020";
    }
    else if (arg == "slideshow_collections") 
    {	call_url = call_url + "9868&subsectionid=151746";
    }
    else if (arg == "slideshow_cookbook") 
    {	call_url = call_url + "9868&subsectionid=151787";
    }
    else if (arg == "slideshow_foodinmag") 
    {	call_url = call_url + "9868&subsectionid=151785";
    }
    else if (arg == "slideshow_style") 
    {	call_url = call_url + "9889&subsectionid=151804";
    }

    $("#slideshowContainerAWW").html('<div id="slideshowLoadingAWW"><img src="/share/img/ajax-loader.gif" />Loading slideshows...</div>');
    
    $.ajax({
        url: call_url,
        cache: false,
        success: function(html){
            if (html.indexOf('headerimage')>-1) {
                $("#slideshowContainerAWW").html(html);
                if (typeof(setConHgt) == 'function') {
                    //force a re-calculation on the height of content column
                    $("#contentcol").css("height", "auto");
                    setConHgt();
                }
            } else {
                $("#slideshowContainerAWW").html("Sorry, no slideshow found at the moment");
            }
        },
        error: function(html){
            $("#slideshowContainerAWW").html("Sorry, no slideshow available at the moment");
        }
    });
}



