var originalFontSize = 12;

jQuery(function(){
    var i = 1;
    var cid = 0;
	var choosenFontSize;
    
    try {
      choosenFontSize = parseFloat(Cookie.get("ChoosenFontSize"), 10);
    } catch (e) {
      choosenFontSize = originalFontSize;
    };
	
    jQuery('.tr-right .moduletable h3:first').css({
            'margin-top': 0,
            'border-top': 0
        }
    );
    
    jQuery('ul#ja-cssmenu > li').each(function(){
        
        this.pid = i;
        
        jQuery(this).addClass('tl-p'+i)
                    .addClass('top-level')
                    .children('ul').each(function(){
                        jQuery(this).addClass('l1')
                                    .addClass('l1-p'+i)
                                    .children('li').children('ul').each(function(){
                                        jQuery(this).addClass('l2')
                                                    .addClass('l2-p'+i)
                                                    .find('ul').hide();
                                    });
                    });
                    
        jQuery(this).children('ul').find('a span').prepend('&raquo; ');
                    
        // Hover 1 level
        jQuery(this).hover(
                    function(){
                        var x, y;
                        var pos = jQuery(this).offset();
                        y = pos.top + 49;
                        if(this.pid <= 3){x = pos.left;}
                        if(this.pid == 4){x = pos.left;}
                        if(this.pid > 4) {x = pos.left-76;}
                        jQuery(this).find('ul.l1-p'+this.pid)
                                    .css({
                                        'left': x,
                                        'top': y
                                    })
                                    .slideDown("fast");
                    },
                    function(){
                        jQuery(this).find('ul.l1-p'+this.pid)
                                    .slideUp("fast");
                    }
        );
                    
        // Hover 2 level
        jQuery(this).children('ul').find('li').hover(
                    function(){
                        
                        var x, y;
                        var pos = jQuery(this).offset();
                        
                        var pid;
                        jQuery(this).parent().each(function(){pid = this.className;});                        
                        pid = pid.match(/l1-p(\d)/);
                        
                        if(!pid) return; // Return if null
                        
                        pid = pid[1];
                        
                        y = pos.top - 194;
                        if(pid <= 3){x = 218;}
                        if(pid == 4){x = -218;}
                        if(pid > 4) {x = -218;}
                        jQuery(this).addClass('act' + pid)
                                    .find('ul.l2-p'+pid)
                                    .css({
                                        'left': x,
                                        'top': y
                                    })
                                    .slideDown("fast");
                    },
                    function(){
                        var pid;
                        jQuery(this).parent().each(function(){pid = this.className;});
                        pid = pid.match(/l1-p(\d)/);
                        
                        if(!pid) return; // Return if null
                        
                        pid = pid[1];
                        
                        jQuery(this).removeClass('act'+pid)
                                    .find('ul.l2-p'+pid)
                                    .slideUp("fast");
                    }
        );
        i++;
    });
    
    i = 1;
    var clrs = ['#d73729', '#f48e04', '#f5d623', '#98ca47', '#3369f7', '#005ba4'];
    jQuery('.xmap .level_0 > li > a').each(function(){
        jQuery(this).attr('id', 'map' + i).css('color', clrs[i-1]);
        i++;
    })
    
    jQuery('#left .moduletable h3').each(function(){ 
        jQuery(this).html('<span>'+jQuery(this).text()+'</span>') 
    });
    
    if(jQuery.browser.msie) jQuery('#foot-menu').css('margin-top', '22px');
    jQuery('#foot-menu ul li').not(':last').append('|');
    
    jQuery('#ja-cssmenu a.active span').each(function(){
        var text = jQuery(this).text();
        var cls  = '';
        
        jQuery(this).parent().parent().each(function(){cls = this.className;});
        cls = cls.match(/tl-p(\d)/);
        
        if(!cls) return; // if null
        cid = cls[1];
        cls = 'tl-p' + cid;
        
        jQuery('#left .moduletable h3').addClass(cls)
                                       .find('span:first')
                                       //.text(text)
                                       .end()
                                       .parent()
                                       .addClass('m-' + cls);
        var img_id = cid<=5?(parseInt(cid) + 1):(1);
        
        jQuery('#left .menulmenu').parent().find('h3 span').text(text);
        //jQuery('#img').html('<img src="http://www.georgensgmuend.info/templates/georg/images/img' + img_id + '.jpg"');
        
        jQuery('#main-table td.line').addClass('l-' + cls);
        
    })
    
    var name = '';
    
    if(cid == 1) name = 'welcome';
    if(cid == 2) name = 'leben';
    if(cid == 3) name = 'politik';
    if(cid == 4) name = 'tourist';
    if(cid == 5) name = 'wirtschaft';
    
    name = name?name:'welcome';
    
    var so = new SWFObject('templates/georg/flash/menu_' + name + '.swf', 'menu-flash', '713px', '102px', '8', '#FFFFFF');
        so.addParam('menu', 'false');
        so.useExpressInstall('templates/georg/swfobject/expressinstall.swf');
        so.write('flash');
    
    var so = new SWFObject('templates/georg/panel.swf', 'menu-panel', '265px', '90px', '8', '#FFFFFF');
        so.addParam('menu', 'false');
        so.useExpressInstall('templates/georg/swfobject/expressinstall.swf');
        so.write('panel');

	jQuery('html').css('font-size', choosenFontSize);

});

      // Increase Font Size
    function incFont(){
        var currentFontSize = jQuery('html').css('font-size');
        var currentFontSizeNum = parseFloat(currentFontSize, 10);
        var newFontSize = currentFontSizeNum+1;
        if(newFontSize<16)
        jQuery('html').css('font-size', newFontSize);
        Cookie.set("ChoosenFontSize", newFontSize,{duration:365});
       // return false;
    };

    // Decrease Font Size
    function decFont(){
        var currentFontSize = jQuery('html').css('font-size');
        var currentFontSizeNum = parseFloat(currentFontSize, 10);
        var newFontSize = currentFontSizeNum-1;
        if(newFontSize>8)
        jQuery('html').css('font-size', newFontSize);
        Cookie.set("ChoosenFontSize", newFontSize,{duration:365});
       // return false;
    };
    
        
    function clearFont(){
        jQuery('html').css('font-size', originalFontSize);
        Cookie.set("ChoosenFontSize", originalFontSize,{duration:365});
       // return false;
    };
