/* Eksakte Frontend - javascript functions */
/* RDC 03.11.2009 */

/*
//Load ajax function
function LoadDiv(toLoad) {
$('#overlay').show(0);							  
$('#productWrapper').hide('fast');
$('#load').remove();
$('#wrapper').append('<span id="load">LOADING...</span>');
$('#load').fadeIn('normal');
$('#productWrapper').load(toLoad,'', function (){
$('#productWrapper').show('normal');
$('#load').fadeOut('normal');
});
}
*/


$(document).ready(function() {
	/*Begin document ready function*/

	$('.CompleteTextLink').click(function() {
                if ($('.CompleteText').is(":hidden")) {
		    $('.CompleteText').css("visibility", "visible");
		    $('.CompleteSubTitleText').css("visibility", "hidden");
		    $('.CompleteSubTitleText').css("display", "none");
                    $('.CompleteText').slideDown("slow");
                } else {
                    $('.CompleteText').hide();
		    $('.CompleteText').css("visibility", "hidden");
                }
            });

	/*Ad Gallery plugin*/
	$('.ad-gallery').not('.dialogContainer').adGallery({
		cycle: true,
		display_next_and_prev: false,
		display_back_and_forward: false
	});

	$('.dialogContainer').dialog({
		autoOpen: false,
		width: 730,
		modal: true, 
		resizable: false 
	});

	// Dialog Link
	$('.dialog_link').click(function() {
		var dialogLinkid = $(this).attr("id").replace("dialog_link_", "");
		$('#dialog_' + dialogLinkid).dialog('open');
		$('#dialog_' + dialogLinkid).not('.adGalleryApplied').addClass('adGalleryApplied').adGallery({
			cycle: true,
			display_next_and_prev: false,
			display_back_and_forward: false
		});
		return false;
	});

//	$('#switch-effect').change(
//		function() {
//			galleries[0].settings.effect = $(this).val();
//			return false;
//		}
//	);
//	$('#toggle-slideshow').click(
//		function() {
//			galleries[0].slideshow.toggle();
//			return false;
//		}
//	);

	/*Ad Gallery customization*/
	$(".mImageGallery .navigation .thumbs ul.list li:last").addClass("last"); /*tiltag for at sidste thumb flugter med det store billedes højrekant*/

	//$(".mImageGallery .navigation .thumbs ul.list li a.ad-active").removeAttr("href");/*for at undgå at det aktive billede hentes igen*/


	//context.showImage();


	//Navigation submenu (IE6)
	$('#header ul li div').hover(
		function() { $('ul', this).css('display', 'block'); },
		function() { $('ul', this).css('display', 'none'); });

	//Show mLogin  	
	$('#header ul li.login').click(function() {
		//console.log($(".mLogin").is(":visible"));
		if ($(".mLogin").is(":visible")) {
			$('.mLogin').hide();
		}
		else {
			$('.mLogin').show();
		} 
	});
	$(document).click(function(event) {
		//console.log(event.target);
		if ($(event.target).parents(".mLogin").size() == 0 && $(event.target).hasClass("mLogin") == false && $(event.target).is("#header ul li.login *") == false) {
			$(".mLogin").hide();
			//$(".filterElement.selected").removeClass("selected");
		}
	});

	//Show mSearch  	
	$('#header ul li.search').click(function() {
		if ($(".mSearch").is(":visible")) {
			$('.mSearch').hide();
		}
		else {
			$('.mSearch').show();
		} 
	});
	$(document).click(function(event) {
		if ($(event.target).parents(".mSearch").size() == 0 && $(event.target).hasClass("mSearch") == false && $(event.target).is("#header ul li.search *") == false) {
			$(".mSearch").hide();
		}
	});



	// Image background slider/fader				// type: Type of slideshow: 'sequence', 'random' or 'random_start' (Default: 'sequence')
	// animationtype: Type of animation 'fade' or 'slide' (Default: 'fade')

	$('.mImageSlide1').innerfade({
		animationtype: 'fade',
		speed: 1500,
		timeout: 5000,
		type: 'sequence',
		containerheight: '560px'
	});
	/*
	$('ul#portfolio').innerfade({
	speed: 1000,
	timeout: 5000,
	type: 'sequence',
	containerheight: '220px'
	});
		
	$('.fade').innerfade({
	speed: 1000,
	timeout: 6000,
	type: 'random_start',
	containerheight: '1.5em'
	});
		
	$('.adi').innerfade({
	speed: 'slow',
	timeout: 5000,
	type: 'random',
	containerheight: '150px'
	});
	*/


	/*
	$('.mLogin').mouseout(function() {
	$('.mLogin').css('display', 'none');
	return false;
	});
	*/





	/*
	//Load ajax - call function
	$('#nav li a').click(function() {
	var toLoad = $(this).attr('href') + ' #productPage';
	LoadDiv(toLoad);
	return false;
	});
    
    
    
	//Unload ajax pages
	$('#productPage a.closeButton').live("click", function() {
	$('#productWrapper').hide();
	$('#productPage').remove();
	$('#overlay').hide();
	});
    



    //Load Flash
	$('.video').flash(
	{ src: '/css/graphics/flash/flamme.swf',
	width: 110,
	height: 120,
	menu: false,
	wmode: 'transparent'
	},
	{ version: 6 }
	);
	*/


	//Load lightbox for the Floor plans
	$('a[rel*="lightbox"]').lightBox(); // Select all links that contains lightboxy in the attribute rel


	/*End document ready function*/
});