function startLightbox()
{
	setInterval("changeImage()", 3000);
}

var image= "", image_i = 0;
function changeImage()
{
	image = getNextImage();
	
	if(image_i < 6){
		image_i++;
	}else{
		image_i = 0;
	}
	
	var width, height;
	if(image_i % 2 == 0){
		width = "100%";
		height = "100%";
	}else{
		width = "100%";
		height = "100%";
	}
	
	$("#lightbox_image_" + image_i).animate(
		{
			width: width,
			height: height,
			opacity: 0
		},
		1000,
		"swing",
		function()
		{
			$("#lightbox_image_" + image_i).attr("src", image)
		}
	);
	$("#lightbox_image_" + image_i).animate(
		{
			width: "100%",
			height: "100%",
			opacity: 1
		},
		1000,
		"swing",
		function()
		{
			$("#lightbox_image_" + image_i).attr("src", image)
		}
	);
	
	//$("#lightbox_image_" + image_i).slideUp("normal", function(){$("#lightbox_image_" + image_i).attr("src", image)});
	//$("#lightbox_image_" + image_i).slideDown("normal");
}

var language_positions = new Array(
	new Array(182, 0),		//new Array(260, 10),
	new Array(105, 70),		//new Array(170, 110),
	new Array(70, 140),		//new Array(100, 210),
	new Array(42, 210),		//new Array(60, 310),
	new Array(35, 280),		//new Array(50, 410),
	new Array(35, 350),		//new Array(50, 510),
	new Array(42, 420),		//new Array(60, 610),
	new Array(70, 490),		//new Array(100, 710),
	new Array(98, 560),		//new Array(140, 810),
	new Array(168, 630)		//new Array(240, 910)
);
var x_offset, y_offset;

function startLanguageImageCarousel()
{
	setTimeout("rotateCarouselImages()", 2000);
}

var index_offset = 1;
function rotateCarouselImages()
{
	for(var i = 0; i < language_positions.length; i++)
	{
		animateCarouselImage(i);
	}
	index_offset++;
	if(index_offset >= language_positions.length)
		index_offset = 0;
	setTimeout("rotateCarouselImages()", 4000);
}

function animateCarouselImage(i)
{
	x_offset = (document.documentElement.clientWidth / 2) - 440;
	y_offset = 60;
	
	var position_index = i + index_offset;	
	if(position_index >= language_positions.length)
		position_index -= language_positions.length;
	
	var x = x_offset + language_positions[position_index][0];
	var y = y_offset + (position_index * 60);
	var opacity = 0.7;
	var height = 45;
	var width = 70;
	
	if(position_index == 0)
	{
		opacity = 0
		
		$("#language_image_"+i).animate(
			{
				left: -100,
				top: -100,
				opacity: opacity,
				height: height,
				width: width
			},
			1000,
			"swing",
			function()
			{
				$("#language_image_"+i).attr("src", getNextImage());
			}
		);
		
		y += 40;
		x += 40;
		height = 187;
		width = 230;
		opacity = 1;
	}
	
	$("#language_image_"+i).animate(
		{
			top: y,
			left: x,
			opacity: opacity,
			height: height,
			width: width
		},
		1000,
		"swing"
	);
}

var js_images_i = 0;
function getNextImage()
{
	js_images_i++;
	if(js_images_i >= js_images.lenght)
		js_images_i = 0;
	return js_images[js_images_i];
}

function animatePage()
{
	$(".btn_navigation").hover(function()
	{
		$(this).find(".nav_icon")
		.animate({ top:"-8px"}, 200).animate({ top:"4px"}, 200) // first jump
		.animate({ top:"-5px"}, 100).animate({ top:"4px"}, 100) // second jump
		.animate({ top:"-3px"}, 100).animate({ top:"4px"}, 100); // the last jump
	}, function(){});
	
	$(".fade").fadeIn(1500);
	$(".fade").css("visibility", "visible");
	
	//$(".slideDown").hide(0, function(){$(this).css("visibility", "visible");});
	$(".slideDown").slideDown(1000);
	$(".slideDown").css("visibility", "visible");
	
	$('.admin_tool').fadeTo("fast", 0.4);
	$('#nav_admin_active').fadeTo("fast", 1);
	
	$('.admin_tool').mouseover(function(){
		if($(this).attr("id") != "nav_admin_active")
			$(this).fadeTo("fast", 1);
	}).mouseout(function(){
		if($(this).attr("id") != "nav_admin_active")
			$(this).fadeTo("fast", 0.4);
    });
}

function animatePageExit()
{
	$("#nav_active").removeAttr("id");
	$(this).attr("id", "nav_active");
	
	$("#content").fadeOut(1000);
}

function ConvertToTinyMCE(id)
{
	$(".edit_tools").fadeOut(1000);
	
	$('#' + id).tinymce({
		script_url : basedir + 'lib/scripts/tiny_mce/tiny_mce.js',
		mode : "elements",
		theme : "advanced",
		skin : "o2k7",
		plugins : "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,filemanager,imagemanager",
		
		// Theme options
		theme_advanced_buttons1 : "save,cancel,|,bold,italic,underline,strikethrough,|,formatselect,fontselect,fontsizeselect",
		theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,|,preview,|,forecolor,backcolor",
		theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,|,sub,sup,|,charmap,emotions,media,advhr,|,fullscreen,|,insertfile,insertimage",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_statusbar_location : "bottom",
		theme_advanced_resizing : true
	});
}

function Convertdobiss_ambiance_house()
{
	ConvertToFancybox("dobiss_ambiance_house");
}

function Convertdobiss_evolution_house()
{
	ConvertToFancybox("dobiss_evolution_house");
}

function ConvertToFancybox(id)
{
	$('#'+id).fancybox({
		'zoomSpeedIn': 300,
		'zoomSpeedOut': 300,
		'overlayShow': true,
		'imageScale': false,
		'centerOnScroll': true,
		'frameWidth': 1070,
		'frameHeight': 550,
		'padding': 0
	});
}

function addClipboardEvents()
{
	var clipboard_ok = $.clipboardReady(function(){
		$(".admin_tool_copy").click(function(){
			var arr_id =  $(this).attr("id").split("_");
			var temp_id = "#temp_" + arr_id[arr_id.length-1];
			$.clipboard($(temp_id).text());
			return false;
		});
	}, { swfpath: site_root + "lib/scripts/jquery.clipboard-2.0.1/jquery.clipboard.swf", debug: false } );
	
	if(clipboard_ok == false)
	{
		$(".admin_tool_copy").hide();
	}
}

function addEvents()
{
	$(".btn_navigation").click(animatePageExit);
}

function addLoadEvents(func) 
{
	if (!document.getElementById) return;
	var oldonload = window.onload;
	if (typeof window.onload != 'function')
	{
		window.onload = func;
	}
	else 
	{
		window.onload = function() 
		{
			oldonload();
			func();
		}
	}
}

addLoadEvents(animatePage);
addLoadEvents(addEvents);