function setBg(tag)
{
	if($(tag+' ul.the_menu').css("display")=="none"){
		 $(tag+' div.header').attr("class","header")
	}else if($(tag+' ul.the_menu').css("display")=="block"){
		 $(tag+' div.header').addClass("header-over")
	}	

}
function Menu(menu) {
    
    this.menu = menu;
	$(this.menu+' .header').click(function () {
	   
	   $(menu).attr("class","")
	   $('.menu ul.the_menu').slideUp('medium',function (){$('.menu div.header').attr("class","header")});
	   $(menu).attr("class","menu");
	   $(menu+' ul.the_menu').slideToggle('medium',function (){setBg(menu)});
	   
	});
	
	$(this.menu+' .header').mouseout(function (){ 
		if($(menu+' ul.the_menu').css('display')=='none'){
			 $(this).attr('class','header')
		}else if($(menu+' ul.the_menu').css('display')=='block'){
			 $(this).addClass('header-over')
		}	
	 })
	 
	 $(this.menu+' .header').mouseover(function (){ $(this).addClass("header-over") })
	 $(this.menu+' .top-middle').mouseover(function (){ $(this).addClass("top-middle-hover") })
	 $(this.menu+' .top-middle').mouseout(function (){  $(this).attr("class","top-middle") })
	 $(this.menu+' .bottom').mouseover(function (){ $(this).addClass("bottom-hover") })
	 $(this.menu+' .bottom').mouseout(function (){  $(this).attr("class","bottom") })
	 
	 
	 $(document).bind('click', function(e) {
       var $clicked = $(e.target);
	   if (! $clicked.parents().hasClass("menu"))
	    $(menu+' ul.the_menu').slideUp('medium',function (){setBg(menu)});
       });
	 
}

$(document).ready(function() {
	
	 
//    var menu1 = new Menu("#menu1");
//    var menu2 = new Menu("#menu2");
//    var menu3 = new Menu("#menu3");
	
	
	$(".dropdown img.flag").addClass("flagvisibility");

    $(".dropdown dt a").click(function() {
        $(".dropdown dd ul").slideToggle('medium');
    });
                
    $(".dropdown dd ul li a").click(function() {
        var text = $(this).html();
        $(".dropdown dt a span").html(text);
        $(".dropdown dd ul").slideToggle('medium');
        $("#result").html("Selected value is: " + getSelectedValue("sample"));
    });
                
    function getSelectedValue(id) {
        return $("#" + id).find("dt a span.value").html();
    }

    $(document).bind('click', function(e) {
        var $clicked = $(e.target);
		if (! $clicked.parents().hasClass("dropdown"))
            $(".dropdown dd ul").slideUp('medium');
    });


    $("#flagSwitcher").click(function() {
        $(".dropdown img.flag").toggleClass("flagvisibility");
    });
	
		$(".dropdownbig img.flag").addClass("flagvisibility");

    $(".dropdownbig dt a").click(function() {
        $(".dropdownbig dd ul").slideToggle('medium');
    });
                
    $(".dropdownbig dd ul li a").click(function() {
        var text = $(this).html();
        $(".dropdownbig dt a span").html(text);
        $(".dropdownbig dd ul").slideToggle('medium');
        $("#result").html("Selected value is: " + getSelectedValue("countrydd0"));
    });
                
    function getSelectedValue(id) {
        return $("#" + id).find("dt a span.value").html();
    }

    $(document).bind('click', function(e) {
        var $clicked = $(e.target);
		if (! $clicked.parents().hasClass("dropdownbig"))
            $(".dropdownbig dd ul").slideUp('medium');
    });
	
	$(".dropdownbig1 img.flag").addClass("flagvisibility");

    $(".dropdownbig1 dt a").click(function() {
        $(".dropdownbig1 dd ul").slideToggle('medium');
    });
                
    $(".dropdownbig1 dd ul li a").click(function() {
        var text = $(this).html();
        $(".dropdownbig1 dt a span").html(text);
        $(".dropdownbig1 dd ul").slideToggle('medium');
        $("#result").html("Selected value is: " + getSelectedValue("countrydd"));
    });
                
    function getSelectedValue(id) {
        return $("#" + id).find("dt a span.value").html();
    }

    $(document).bind('click', function(e) {
        var $clicked = $(e.target);
		if (! $clicked.parents().hasClass("dropdownbig1"))
            $(".dropdownbig1 dd ul").slideUp('medium');
    });


    $("#flagSwitcher").click(function() {
        $(".dropdownlarge img.flag").toggleClass("flagvisibility");
    });
	
	$(".dropdownlarge img.flag").addClass("flagvisibility");

    $(".dropdownlarge dt a").click(function() {
        $(".dropdownlarge dd ul").slideToggle('medium');
    });
                
    $(".dropdownlarge dd ul li a").click(function() {
        var text = $(this).html();
        $(".dropdownlarge dt a span").html(text);
        $(".dropdownlarge dd ul").slideToggle('medium');
        $("#result").html("Selected value is: " + getSelectedValue("contacttypedd"));
    });
                
    function getSelectedValue(id) {
        return $("#" + id).find("dt a span.value").html();
    }

    $(document).bind('click', function(e) {
        var $clicked = $(e.target);
		if (! $clicked.parents().hasClass("dropdownlarge"))
            $(".dropdownlarge dd ul").slideUp('medium');
    });


    $("#flagSwitcher").click(function() {
        $(".dropdownlarge img.flag").toggleClass("flagvisibility");
    });

    $(".dropdownxlarge dt a").click(function() {
        $(".dropdownxlarge dd ul").slideToggle('medium');
    });
                
    $(".dropdownxlarge dd ul li a").click(function() {
        var text = $(this).html();
        $(".dropdownxlarge dt a span").html(text);
        $(".dropdownxlarge dd ul").slideToggle('medium');
        $("#result").html("Selected value is: " + getSelectedValue("subjectdd"));
    });
                
    function getSelectedValue(id) {
        return $("#" + id).find("dt a span.value").html();
    }

    $(document).bind('click', function(e) {
        var $clicked = $(e.target);
		if (! $clicked.parents().hasClass("dropdownxlarge"))
            $(".dropdownxlarge dd ul").slideUp('medium');
    });


    
	
	
    $(".dropdownxsmall dt a").click(function() {
        $(".dropdownxsmall dd ul").slideToggle('medium');
    });
                
    $(".dropdownxsmall dd ul li a").click(function() {
        var text = $(this).html();
        $(".dropdownxsmall dt a span").html(text);
        $(".dropdownxsmall dd ul").slideToggle('medium');
        $("#result").html("Selected value is: " + getSelectedValue("langdd"));
    });
                
    function getSelectedValue(id) {
        return $("#" + id).find("dt a span.value").html();
    }

    $(document).bind('click', function(e) {
        var $clicked = $(e.target);
		if (! $clicked.parents().hasClass("dropdownxsmall"))
            $(".dropdownxsmall dd ul").slideUp('medium');
    });
});
 
