// Event Handlers
function CurrencyDropdownEnd(curName, curId, url, open) {
    if ($("#currency .dropdown").css('display') == 'none') {
    	var html = '';
    	for (var i = 0; i < curName.length; i++) {
    		if (curId[i]) {
    			html += '<a href="' + url + curId[i] + '">' + curName[i] + '</a>';
    		}
    		else {
    			html += '<b>' + curName[i] + '</b>';
    		}
    	}
    	$("#currency .dropdown").html(html);
        $("#currency .dropdown a").click(function(e){
	    	$("#currency .dropdown").hide();
        })
        if (open) {
    		$("#currency .dropdown").show();
    	}
    }
} 

function SortingDropdownEnd(name, url, open) {
    if ($(".nav-category .right .dropdown").css('display') == 'none') {
    	var html = '';
    	for (var i = 0; i < name.length; i++) {
    		if (url[i]) {
    			html += '<a href="' + url[i] + '">' + name[i] + '</a>';
    		}
    		else {
    			html += '<b>' + name[i] + '</b>';
    		}
    	}
    	$(".nav-category .right .dropdown").html(html);
        $(".nav-category .right .dropdown a").click(function(e){
	    	$(".nav-category .right .dropdown").hide();
        })
        if (open) {
    		$(".nav-category .right .dropdown").show();
    	}
    }
}


function CurrencyClick() {
    if ($("#currency .dropdown").css('display') != 'none') {
    	$("#currency .dropdown").hide();
        $(document).removeAttr("onclick").unbind('click');
    }
    else {
		if (($("#currency .dropdown").html() == "&nbsp;") || (jQuery.trim($("#currency .dropdown").html()) == "")) {
    		CurrencyDropdown(true);
    	}
    	else {
    		$("#currency .dropdown").show();
    		$("#currency .dropdown").focus();
    	}
    }
}

function SortingClick() {
    if ($(".nav-category .right .dropdown").css('display') != 'none') {
    	$(".nav-category .right .dropdown").hide();
    } else {
		if (($(".nav-category .right .dropdown").html() == "&nbsp;") || (jQuery.trim($(".nav-category .right .dropdown").html()) == "")) {
			SortingDropdown(true);
    	} else {
    		$(".nav-category .right .dropdown").show();
    	}
    }
} 


$(".catalogue-body .catalogue-all").ready(function(){
    CatalogueAllDropdown();
})

$(document).ready(function(){
    CurrencyDropdown(false);
    $("#currency span").click(function(e){
        CurrencyClick();
    });
	$(document).click(function(event) {
		if (event.target.id != 'currentCurrency') $("#currency .dropdown").hide();
		if (event.target.className != 'currentSort') $(".nav-category .dropdown").hide();
	});
	if ($(".nav-category .right .dropdown").length > 0) {
	    SortingDropdown(false);
    	$(".nav-category .right span").click(function(e){
	    	SortingClick();
    	});
    }
})
