var dc = false;

$(document).ready(function(){
						   		   
	//When you click on a link with class of poplight and the href starts with a # 
	$('a.pu[href^=#]').live('click',function() {
		var popID = $(this).attr('rel'); //Get Popup Name
		var popURL = $(this).attr('val'); //Get Popup href to define size
		get_popup(popID,popURL);
		return false;
	});
	
	//Close Popups and Fade Layer
	$('a.close, #fade').live('click', function() { //When clicking on the close or fade layer...
		pop_cls();
		return false;
	});
	
});

function get_popup(func,para)
{
	//Fade in Background
	$('body').append('<div id="fade"></div>'); //Add the fade layer to bottom of the body tag.
	$('#fade').css({'filter' : 'alpha(opacity=40)'}).fadeIn('fast'); //Fade in the fade layer c
	
	$.ajax({
		type: "POST",
		url: "/popup/", 
		data: "function="+func + "&para=" + para, 
			success: function(msg){
			costom_popup(msg);
			ghotex();
		}
	});
}

function pop_cls()
{
	if(dc!=1)
	{
	  	$('#fade , .popup_block').fadeOut('fast',function() {
			$('#fade, a.close').remove();  
	  	});
	}
}

function costom_popup(msg){
	$('#pop').html(msg);
	
	dc = typeof(dc) != 'undefined' ? dc : 0;

	if(dc!=1)
		$('#pop').prepend('<a href="#" class="close">&nbsp;</a>');
	
	//Fade in the Popup and add close button
	$('#pop').fadeIn("fast");
	
	//Define margin for center alignment (vertical + horizontal) - we add 80 to the height/width to accomodate for the padding + border width defined in the css
	var popMargTop = ($('#pop').height() + 80) / 2;
	var popMargLeft = ($('#pop').width() + 80) / 2;
	
	//Apply Margin to Popup
	$('#pop').css({ 
		'margin-top' : -popMargTop,
		'margin-left' : -popMargLeft
	});	
}

function foto_popup(msg,wid,hei){

	$('#popupfoto').html(msg).append('');

	//Fade in the Popup and add close button
	$('#popupfoto').fadeIn("fast");
	
	//Define margin for center alignment (vertical + horizontal) - we add 80 to the height/width to accomodate for the padding + border width defined in the css
	var popMargTop = hei;
	var popMargLeft = wid;
	
	//Apply Margin to Popup
	$('#popupfoto').css({ 
		'margin-top' : popMargTop,
		'margin-left' : popMargLeft
	});
	
	//Fade in Background
	$('body').append('<div id="dia"><div style="position:absolute;right:15px;top:5px;color:#fff;cursor:pointer;" onclick="javascript:dia_cls();">Schließen</div><div style="position:absolute;bottom:0;width:100%;height:30px;text-align:center;"><div style="-webkit-border-radius:5px;-moz-border-radius:5px;border-radius:5px;background:#202020;width:180px;margin:0 auto;height:20px;padding-top:5px;"><div class="flo_lef" style="color:#fff;padding-left:10px;margin-top:-2px;"><a href="javascript:prev();" style="color:#fff;">zur&uuml;ck</a></div><img id="con_btn" src="http://static.vono.me/images/play.gif" style="padding:5px 15px;cursor:pointer;margin-top:-5px;" /><div class="flo_rig" style="color:#fff;padding-right:10px;margin-top:-2px;"><a href="javascript:next();" style="color:#fff;">weiter</a></div></div></div>'); //Add the fade layer to bottom of the body tag.
	
	$('#dia').css({'filter' : 'alpha(opacity=100)'}).fadeIn('fast'); //Fade in the fade layer 
	
	set_pop = true;
}

function dia_cls()
{
  	$('#dia , .popup_block').fadeOut('fast',function() {
		$('#dia, a.close').remove();  
  	});
  	set_pop = false;
  	set_src(ghash);
}

var switcher = 0;
$('#con_btn').live('click', function() {
	if(switcher == 0){
		dia_start()
		window.setTimeout("dia_run()", 1000);
	}
	else
	{
		dia_stop();
	}

});
var nex_tim;

function dia_run(){
	if(switcher == 1)
	{
		if(nf === false)
			$('#popupfoto').load(function(){
				if(!nex_tim);
				nex_tim = window.setTimeout("dia_run()", 5000);
			});
		else
		{
			next();
			nex_tim = window.setTimeout("dia_run()", 5000);
		}
	}
	else
	{
		dia_stop();
	}
}

function dia_start()
{
	switcher = 1;
	$("#con_btn").attr("src","http://static.vono.me/images/pause.gif");
}

function dia_stop()
{
	switcher = 0;
	$("#con_btn").attr("src","http://static.vono.me/images/play.gif");
	window.clearTimeout(nex_tim);
}

$(document).ready(function() {
	ghotex();
});

function ghotex()
{
	$('.gho-tex').each(function(){
	    var d = $(this).val();
	    $(this).focus(function(){
	        if ($(this).val() == d){
	            $(this).val('').removeClass('gho-tex');
	        }
	    });
	    $(this).blur(function(){
	        if ($(this).val() == ''){
	            $(this).val(d).addClass('gho-tex');
	        }
	    });
	});
}
