/*
 * Frontend JavaScript interaction code for jQuery JavaScript Library v1.4.x
 *
 * Initial version:
 * Copyright (C) 2003-2010
 * Peter Arts, Forwart
 * http://www.forwart.nl
 *
 * Extended and improved version:
 * Copyright (C) 2006-2010
 * Peelweb.nl
 * http://www.peelweb.nl
 */

// Turn off all jquery effects
jQuery.fx.off = true;

// Use variable instead of '$' accessor because lightbox is also using it
var jQ = jQuery.noConflict();

jQ(document).ready(function() {
	
	// open links having rel nofollow in new window
	jQ('a[rel*=nofollow]').click(function(e) {
		e.preventDefault();
		window.open(jQ(this).attr('href'));
	});

	// open links having class blank in new window
	jQ('a[class*=blank]').click(function(e) {
		e.preventDefault();
		window.open(jQ(this).attr('href'));
	});

	// apply label text as placeholder to search query field
	jQ('form#search fieldset input.submit').attr('value', '');
	var searchQ = jQ('form#search input#search_q');
	if (searchQ.length == 1) {
		var defaultText = jQ('form#search label').html();
		if (searchQ.attr('value') == '') {
			searchQ.attr('value', defaultText);
		}
		searchQ.focus(function() {
			if (jQ(this).attr('value') == defaultText) {
				jQ(this).attr('value', '');
			}
		}).blur(function() {
			if (jQ(this).attr('value') == '') {
				jQ(this).attr('value', defaultText);
			}
		});
	}

	jQ('div#wrapper div#header ul#menu li').mouseenter(function() {
        jQ(this).addClass('active'); // Set this class as active

		if (jQ(this).find('ul.submenu').length == 0) {
			// do nothing for submenu items
			return;
		}
		if (jQ(this).find('ul.submenu').hasClass('visible')) {
			// already active, nothing to do
			return; 
		}
		jQ(this).parents('ul#menu').find('li ul.submenu.visible').fadeOut(function() {
			jQ(this).removeClass('visible');
			jQ(this).parents('li').removeClass('subactive');
            jQ(this).parents('li').removeClass('active'); // Remove white background of selected main-item
		});
		jQ(this).find('ul.submenu').fadeIn(function() {
			jQ(this).addClass('visible');
			jQ(this).parents('li').addClass('subactive');
		});
	});

    jQ('a.weather_iframe').each(function (i) {
        jQ(this).replaceWith("<iframe src='" + this.getAttribute("href") + "'  frameborder='0' scrolling='no'></iframe>");
    });
});
