document.createElement('header');
document.createElement('footer');
document.createElement('section');
document.createElement('article');
document.createElement('aside');
document.createElement('nav');

var $j = jQuery.noConflict();

$j(document).ready(function(){
	
	// FILTERS

	$j('.disabled').live('click', function(e) {
		e.preventDefault();
	});
	
	$j("ul#filters li input").click(function () {
	
		var value = $j(this).val();
		
		if (!$j(this).attr("checked")) {
			$j('.category-'+value).stop().fadeTo('slow', 0.2);
			$j('.category-'+value).addClass('disabled');
		}
		else {
			$j('.category-'+value).stop().fadeTo('slow', 1.0);
			$j('.category-'+value).removeClass('disabled');
		}
	});
	
	// MENU STUFF
	//
	// REENABLE WHEN HISTORY IS WORKING
	/*
	$j("li#menu-item-117 a:first").click(function(event){
		event.preventDefault();
		
		$j("ul.sub-menu").stop();
		$j("ul.sub-menu").slideToggle();
	});
	*/
	
	$j("li#menu-item-24 a:first").click(function(event){
		event.preventDefault();
		$j("#contact-info").stop();
		$j("#contact-info").slideToggle();
	});
	
	
	// SCROLLTOTOP
    $j('a[href=#top]').click(function(){
        $j('html, body').animate({scrollTop:0}, 'slow');
        return false;
    });
    
    // LINKS
    $j("a[href^='mailto:']").addClass("link-mail");
    $j("section#content a[href^='http']:not([href^='http://www.nmm.se/'])").addClass("link-external");
    $j("section#content a[href^='http']:not([href^='http://www.nmm.se/'])").attr("target","_blank");
    
    // Remove tooltips on participants thumbnail
    $j(".participants-thumbnail img").attr('title','');
    
    // HEADLINE
    var holder;

	$j("#headline-ticker a").each(function(index, elem){
	    if(index%3==0){
	        holder=$j("<div class='right'></div>").appendTo("#headline-ticker");
	    }
	    
	    holder.append(this);
	});
	
	$j("#headline-ticker").cycle({
		fx: 'fade',
		timeout: 3000,
		pause: 1
	});
	
	//
	// DISABLED ITEMS
	//
	//$j("#menu-item-74").addClass("disabled");
	$j("#menu-item-117").addClass("disabled");
	
	//$j("#menu-item-74 a").attr("href", "");
	$j("#menu-item-117 a").attr("href", "");
	
	//$j("#menu-item-74").attr("title", "Coming Soon...");
	$j("#menu-item-117").attr("title", "Coming Soon...");
	
	$j("nav .disabled a").each(function() {
		var oldValue = $j(this).text();
		$j(this).hover(function(){
			console.log(oldValue);
			$j(this).text("Coming Soon...");
		},
		function() {
			$j(this).text(oldValue);
		});
	});
	
	//
	// VERT ALIGN
	//
	//$j("dt.gallery-icon").vAlign();
	
	$j("article.participants-thumbnail img").each(function(){
		var topmargin = 90 - $j(this).height()/2;
		var bottmargin = 90 - $j(this).height()/2;
		$j(this).css('marginTop', topmargin);
		$j(this).css('marginBottom', bottmargin);
	});
});

$j(window).load(function () {
	$j("dt.gallery-icon img").each(function(){
		var topmargin = 72 - $j(this).height()/2;
		$j(this).css('paddingTop', topmargin);
	});
});

(function ($j) {
	$j.fn.vAlign = function(container) {
		return this.each(function(i){
			if(container == null) {
				container = 'div';
			}
			$j(this).html("<" + container + ">" + $j(this).html() + "</" + container + ">");
			var el = $j(this).children(container + ":first");
			var elh = $j(el).height(); //new element height
			var ph = $j(this).height(); //parent height
			var nh = (ph - elh) / 2; //new height to apply
			$j(el).css('margin-top', nh);
		});
	};
})(jQuery);
