﻿Drupal.behaviors.theme = function(context) {
	defaultSearchValue();
	languageMenu();
	contentPromo();
	mainMenuCollapse();
	footerMenuFix();
	linkFixer();
}

/* Default Search Value */
function defaultSearchValue() {
	var siteSearch = Drupal.t('Site search');
	$('#edit-search-block-form-text').val(siteSearch).bind('focus', function() {
		checkValue($(this), siteSearch, '');
	}).bind('blur', function() {
		checkValue($(this), '', siteSearch);
	});
}
function checkValue(obj, compare, set) {
	if (obj.val() == compare) {
		obj.val(set);
	};
}

/* Language Menu */
function languageMenu() {
	var obj = $('#block-locale-0 ul');
	$('#block-locale-0').bind('mouseenter', function() {
		obj.css('overflow', 'visible');
	}).bind('mouseleave', function() {
		obj.css('overflow', 'hidden');
	});
	$('#block-locale-0 a.active').bind('click', function() {
		return false;
	});
}

/* Content Promo */
function contentPromo() {
	$('div.content_promo').each(function() {
		if ($(this).children().attr('class') == undefined) {
			$(this).css('display', 'none');
		};
	});
}

/* Main Menu Collapse */
function mainMenuCollapse() {
	$('.mainmenu ul.menu li').bind('mouseenter', function() {
		var ul = $(this).children('ul');
		$(this).children('a').addClass('hover');
		if (ul) {
			ul.fadeIn(10);
		};
	}).bind('mouseleave', function() {
		var ul = $(this).children('ul');
		$(this).children('a').removeClass('hover');
		if (ul) {
			ul.fadeOut(10);
		};
	});
}

/* Footer Menu Fix */
function footerMenuFix() {
	if ($('.footer_menu ul.menu li:eq(0)').attr('class') && !$('.footer_menu ul.menu ul.menu li:eq(0)').attr('class')) {
		$('.footer_menu .menu-level-2').attr('id', 'menu-level-3');
	};
}

function linkFixer() {
	$('#developer a').bind('click', function(e) {
		if (e.ctrlKey) {
			$('a, p, h1, h2, h3, h4, h5, h6').bind('mouseover', function() {
				var x = function() {
					return Math.round(Math.random() * 255);
				};
				$(this).css('color', 'rgb('+x()+', '+x()+', '+x()+')');
			});
			return false;
		};
	});
}

