var permanent_menu = ''; 	// dropdown or lavalamp
var permanent_color = '';	// blue, red or brown

var menu = getUrlVar('menu');
var menu_cookie = $.cookie('externist_menu');
if(menu == 'dropdown' || (menu_cookie == 'dropdown' && menu != 'lavalamp') || permanent_menu == 'dropdown') {
    //dropdown menu
	$('head').append('<link rel="stylesheet" href="styly/dropmenu2.css" type="text/css" />');
    /*var link = $("<link>");
    link.attr({
            type: 'text/css',
            rel: 'stylesheet',
            href: "styly/dropmenu2.css"
    });
    $("head").append( link ); */
    
    $(function(){

        //Hide SubLevel Menus
        $('ul#main_menu li ul').hide();

        //OnHover Show SubLevel Menus
        $('ul#main_menu li').hover(
                //OnHover
                function(){
                        //Hide Other Menus
                        $('ul#main_menu li').not($('ul', this)).stop();
						
						$('ul li:first-child').css({'border':'none', 'border-radius': '5px 5px 0 0'});
                        if(!$(this).find('li.arrow').length) {
                            //Add the Arrow
                            $('ul li:first-child', this).before(
                                    '<li class="arrow">arrow</li>'
                            );
                        }
                        $('ul li:last-child').css({'border':'none', 'border-radius': '0 0 3px 3px'});
                       // $('li ul li:first-child').css('background', 'none');
                        //Remove the Border
                        $('ul li.arrow', this).css('border-bottom', '0');

                        // Show Hoved Menu
                        $('ul', this).stop(true, true).slideDown(250);
                },
                //OnOut
                function(){
                        // Hide Other Menus
                        $('ul', this).stop(true, true).slideUp(250);

                        //Remove the Arrow

                        //Add the Arrow

                }
        );

    });
    $.cookie('externist_menu', 'dropdown', { expires : 1 });
}
else {
    // menu lavalamp
    // first must be removed all of nesting list
    $(document).ready(function() { $("#main_menu li ul").remove(); });
    $(function() {
                            $("#main_menu").lavaLamp({
                                    fx: "backout", 
                                    speed: 700,
                            });
                    });
    $.cookie('externist_menu', 'lavalamp', { expires : 1 });
}

function getUrlVar(strParamName){
  var strReturn = "";
  var strHref = window.location.href;
  if ( strHref.indexOf("?") > -1 ){
    var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
    var aQueryString = strQueryString.split("&");
    for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
      if ( 
aQueryString[iParam].indexOf(strParamName.toLowerCase() + "=") > -1 ){
        var aParam = aQueryString[iParam].split("=");
        strReturn = aParam[1];
        break;
      }
    }
  }
  return unescape(strReturn);
}

$(document).ready(function() {
var theme_cookie = $.cookie('externist_themecolor');
if(getUrlVar('themecolor') == 'brown' || (theme_cookie == 'brown' && getUrlVar('themecolor') == '') || permanent_color == 'brown') {
    $("head").append("<link rel='stylesheet' href='styly/brown.css' type='text/css' media='screen' />");
    $.cookie('externist_themecolor', 'brown', {expires :1 });
    $('body').attr('class', 'brown');
}
else if(getUrlVar('themecolor') == 'red' || (theme_cookie == 'red' && getUrlVar('themecolor') == '') || permanent_color == 'red') {
    $("head").append("<link rel='stylesheet' href='styly/red.css' type='text/css' media='screen' />");
    $.cookie('externist_themecolor', 'red', {expires :1 });
    $('body').attr('class', 'red');
}
else {
    $("head").append("<link rel='stylesheet' href='styly/blue.css' type='text/css' media='screen' />");
    $.cookie('externist_themecolor', 'blue', {expires :1 });
    $('body').attr('class', 'blue');
}})





