/*
jQuery menu

Example:
$(document).ready(function()
{
    $('#jmenu').jmenu({animation:'fade',duration:100});
});

(c) 2010 Sawanna Team (http://sawanna.org)
*/

var jmenu={
    effect: 'fade',           /* default animation effect */
    duration: 400,         /* default duration */
    set: function (settings)
    {
	
	
	activelink=$('ul#jmenu ul li a.active');
	$('<a href='+activelink.attr('href')+' class="xactive">'+activelink.html()+'</a>').insertBefore(activelink.parent('li').parent('ul'));
	activelink.parent('li').parent('ul').addClass('xxactive');
	

       try
        {
            if (settings.animation == 'show') { this.effect='show'; }
            if (settings.animation == 'slide') { this.effect='slide'; }
            if (settings.animation == 'fade') { this.effect='fade'; }
        } catch (e) {}
        
        try
        {
            this.duration=settings.duration;
        } catch (e) {} 
    },
    fix_pos:function(elem)
    {
        if ($(elem).parent('ul').parent('li').length)
        {
            $(elem).children('ul').eq(0).css({marginTop:-$(elem).height(),marginLeft:$(elem).width()});
        } else
        {
            $(elem).children('ul').eq(0).css({'top':$(elem).offset().top+$(elem).height(),'left':$(elem).offset().left});
        }
    },
    show:function(elem)
    {
		$(elem).children('ul').css('z-index', '2')
        if (this.effect=='fade') { $(elem).children('ul').eq(0).stop(1,1).fadeIn(this.duration); }
        else if (this.effect=='slide') {$(elem).children('ul').eq(0).stop(1,1).delay(50).slideDown(this.duration); }
        else if (this.effect=='show') { $(elem).children('ul').eq(0).stop(1,1).show(this.duration); }
    },
    hide: function(elem)
    {
		$(elem).children('ul').css('z-index', '1')
        if (this.effect=='fade') { $(elem).children('ul').eq(0).stop(1,1).fadeOut(this.duration); }
        else if (this.effect=='slide') {$(elem).children('ul').eq(0).stop(1,1).delay(100).slideUp(this.duration); }
        else if (this.effect=='show') { $(elem).children('ul').eq(0).stop(1,1).hide(this.duration); }
    }
}

jQuery.fn.jmenu=function(settings)
{
    jmenu.set(settings);
    
    $(this).find('li').each(function()
    {
            $(this).hover(
                function()
                {
                    jmenu.fix_pos(this);
                    jmenu.show(this);
                },
                function()
                {
                    jmenu.hide(this);
                }
            );
    });
}


$(document).ready(function()
{
    $('#jmenu').jmenu({animation:'slide',duration:600});
	
	// Load no-shadow.css-file bei alten Browsern 
	
	if (($.browser.msie)*(parseInt($.browser.version, 10)<9)) {loadNoShadowboxCSS()}
	if (($.browser.webkit)*(parseInt($.browser.version, 10)<532)) {loadNoShadowboxCSS()}
	if (($.browser.safari)*(parseInt($.browser.version, 10)<532)) {loadNoShadowboxCSS()}
	if (($.browser.mozilla)*($.browser.version<3.5)) {loadNoShadowboxCSS()}
	if (($.browser.opera)*($.browser.version<10.53)) {loadNoShadowboxCSS()}
	
	// Insert lines in Navigation
		
	$('ul#jmenu li').each(function() { // Preload all images
		thref=$(this).find("a").attr("href");
		if ((thref=="fotogalerie/")+(thref=="geschichte-der-agentur.html")+(thref=="werbelektorat.html")+(thref=="expose-verfassen.html")) {
			$(this).attr("class","dotted");
			}
	 });

	// Extend list text when there is no photo

	$('div.listbox').each(function() {
		if ($(this).find("img").attr("width")) {$(this).attr("alt",$(this).find("img").attr("width"))} else {
			$(this).find(".listtext").css("width","675px");
		}
		
	});



});


function loadNoShadowboxCSS(){
  var fileref=document.createElement("link")
  fileref.setAttribute("rel", "stylesheet")
  fileref.setAttribute("type", "text/css")
  fileref.setAttribute("href", "assets/templates/css/no-shadow.css") // Hier muss eventuell noch der Pfad angepasst werden
  document.getElementsByTagName("head")[0].appendChild(fileref)
}

