$(document).ready(function () {
	
	// fancybox
	$(".fancybox").each(function() {
		$(this).fancybox();
	});
	
	
	// dropdown
	var openDropDown = null;
	function toggleDropDown(e) {
		if (openDropDown  &&  openDropDown != e.attr('id')) {
			$('#'+openDropDown+'_dropdown').hide();
		}

		if (openDropDown != e.attr('id')) {
			openDropDown = e.attr('id');
			e.parent().find( '#'+e.attr('id')+'_dropdown' )
				.css( 'left', e.position().left )
				.css( 'top', e.position().top + e.outerHeight() )
				.show();
		}else{
			openDropDown = null;
			e.parent().find( '#'+e.attr('id')+'_dropdown' )
				.hide();
		}
	}
	function showDropDown(e) {
		if (openDropDown) {
			$('#'+openDropDown+'_dropdown').hide();
		}

		openDropDown = e.attr('id');
		e.parent().find( '#'+e.attr('id')+'_dropdown' )
			.css( 'left', e.position().left )
			.css( 'top', e.position().top + e.outerHeight() )
			.show();
	}
	$(".dropdownlink").click(function () {
		toggleDropDown( $(this) );
	});
	$(".dropdownlink").mouseenter(function () {
		if (openDropDown) showDropDown( $(this) );
	});
	$(".dropdown a").click(function() {
		$(this).closest(".dropdown").hide();
	});
	
	
	// bkg
	$("#backgroundmenu_dropdown a").click(function(e) {
		$.get($(this).attr('href'), function(data){
			$("body").css("background-color", data);
		});
		return false;
	});
	
});
	

