// JavaScript Document

/*  ListArticles  */
$(document).ready( function() {
	_typeface_js.configure({ disableSelection: true });

    if($.browser.mozilla)
    {
    	$('#naviHauptnavigation > ul > li > a').addClass('typeface-js').css({
    		fontFamily: 'Pigiarniq',
    		textShadow: '1px 1px 1px #484848',
    		fontSize: '17px',
    		color: '#fff',
    		textDecoration: 'none'
    	});
    }
	$('#naviSpezialseiten > ul > li > a').append(' &raquo;');
	$('#naviSpezialseiten > ul').append('<li><a target="_blank" href="http://noblekom.de/n2/?page=recherche@macao">Für Medien &raquo;</a></li>');
	
	/*informationContainer();*/
	
	$('.listarticle').each( function() {
		var listNum = 6;
		var pageNum = 0;
		$(this).find('li').mouseover( function() {
			$(this).addClass('listOver');					 
		});
		$(this).find('li').mouseout( function() {
			$(this).removeClass('listOver');			
		});
		
		var listCant = $(this).find('li').length;
		$(this).find('span span.nrArt').html(listCant);
		if (listCant%listNum == 0) {
			pageCant = parseInt(listCant/listNum);
		}
		else {
			pageCant = parseInt(listCant/listNum)+1;
		}
		$(this).find('li').each( function(i) {
			$(this).addClass('list'+(parseInt(i)+1));
		});
		for ( var k=0; k<=pageCant; k++) {
			for ( var j=(k*listNum)+1; j<=(k*listNum)+listNum; j++) {
				$(this).find('.list'+j).addClass('page'+(parseInt(k)+1));
			}
			if (k>=2) {
				$(this).find('.pager').append('<span class="divisor">|</span><a id="pagNr'+k+'" class="pag">&nbsp;'+k+'&nbsp;</a>');
			}
		}
		
		$(this).find('.pager a').click( function() {
			var clickedPag = $(this).attr('id').substr(5,10);
			//console.log(clickedPag);
			if ($(this).hasClass('pagAct')) {
			}	
			else {
				$(this).parent().find('a.pagAct').removeClass('pagAct');
				$(this).addClass('pagAct');
				$(this).parents('.listarticle').find('li').css({
					display: 'none'
				});
				$(this).parents('.listarticle').find('li.page'+clickedPag).css({
					display: 'block'
				});
				
			}
		});
	
	});

	/*  Footer Bottom  */ /*Leave me at the end*/
	footerbottom();
	$(window).resize( function() {
		footerbottom();				
	});
	

});

/*Navigation*/
$(function(){
        $('.naviHauptnavigation').superfish({
                delay: 500,
                autoArrows: false,
                dropShadows: false
        });
});

function footerbottom() {
	if($('#cmsEditor').length == 0)
	{
		var heightPage = $('#page').attr('clientHeight');
		var heightContent = $('#content').attr('clientHeight');
		var heightHtml = $('html').attr('clientHeight');
		if ( heightPage < heightHtml) {
			$('#content').attr('style','min-height:'+(heightHtml-(heightPage-heightContent+1))+'px');
		}
		else {
			$('#content').removeAttr('style');
			var heightPage = $('#page').attr('clientHeight');
			var heightContent = $('#content').attr('clientHeight');
			var heightHtml = $('html').attr('clientHeight');
			if ( heightPage < heightHtml) {
				$('#content').attr('style','min-height:'+(heightHtml-(heightPage-heightContent+1))+'px');
			}
		}
	}
	else
	{
		var heightPage = $('#page').attr('clientHeight');
		var heightContent = $('#content').attr('clientHeight');
		var heightHtml = ($('html').attr('clientHeight')-70);
		if ( heightPage < heightHtml) {
			$('#content').attr('style','min-height:'+(heightHtml-(heightPage-heightContent+1))+'px');
		}
		else {
			$('#content').removeAttr('style');
			var heightPage = $('#page').attr('clientHeight');
			var heightContent = $('#content').attr('clientHeight');
			var heightHtml = ($('html').attr('clientHeight')-70);
			if ( heightPage < heightHtml) {
				$('#content').attr('style','min-height:'+(heightHtml-(heightPage-heightContent+1))+'px');
			}
		}
	}
}
/****browse button style****/
(function($) {
    
    $.fn.filestyle = function(options) {
                
        /* TODO: This should not override CSS. */
        var settings = {
            width : 250
        };
                
        if(options) {
            $.extend(settings, options);
        };
                        
        return this.each(function() {
            
            var self = this;
            var wrapper = $("<div>")
                            .css({
                                "width": settings.imagewidth + "px",
                                "height": settings.imageheight + "px",
                                "background": "url(" + settings.image + ") 0 0 no-repeat",
                                "background-position": "right",
                                "display": "inline",
                                "position": "absolute",
                                "overflow": "hidden"
                            });
                            
            var filename = $('<input class="file">')
                             .addClass($(self).attr("class"))
                             .css({
                                 "display": "inline",
                                 "width": settings.width + "px"
                             });

            $(self).before(filename);
            $(self).wrap(wrapper);

            $(self).css({
                        "position": "relative",
                        "height": settings.imageheight + "px",
                        "width": settings.width + "px",
                        "display": "inline",
                        "cursor": "pointer",
                        "opacity": "0.0"
                    });

            if ($.browser.mozilla) {
                if (/Win/.test(navigator.platform)) {
                    $(self).css("margin-left", "-142px");                    
                } else {
                    $(self).css("margin-left", "-168px");                    
                };
            } else {
                $(self).css("margin-left", settings.imagewidth - settings.width + "px");                
            };

            $(self).bind("change", function() {
                filename.val($(self).val());
            });
      
        });
        

    };
	
    
})(jQuery);
