var DocumentHeight = 0;
var DocumentWidth = 0;
var VisibleHeight = 0;
var VisibleWidth = 0;

function BlackDiv()
{
	var div = '<div class="BackDiv" id="BlackDiv"></div>';
	div += '<div class="OverBlackDiv" id="OverBlackDiv"></div>';
	$("body").prepend(div);
	document_dimentions();
	$("#BlackDiv").css(
	{
		"width" : DocumentWidth,
		"height" : DocumentHeight
	});
	$("#OverBlackDiv").css(
	{
		"width" : DocumentWidth,
		"height" : DocumentHeight
	});
}

function OverBlackDiv_reposition()
{
	var part = ( VisibleHeight - $("#OverBlackDiv .center_center").height() ) /2;
	$("#OverBlackDiv .center_center").css("margin-top" , part);
}

function BlackDiv_close( paramFade )
{
	paramFade = paramFade || false;
	if( paramFade )
	{
		$("#BlackDiv").fadeOut("fast", function(){ $("#BlackDiv").remove(); });
		$("#OverBlackDiv").fadeOut("fast", function(){ $("#OverBlackDiv").remove(); });
	}
	else
	{
		$("#BlackDiv").remove();
		$("#OverBlackDiv").remove();
	}
}

function confirm_dialog( paramQuestion, paramCallback )
{
	BlackDiv();
	
	var dialog = '<div id="ConfirmDialog" class="center_center">';
	dialog+='<div class="question">'+paramQuestion+'</div>';
	dialog+='<div class="left">';
	dialog+='<a href="javascript:void(0);" id="ConfirmDialog_YES"></a>';
	dialog+='';
	dialog+='</div>';
	dialog+='<div class="right">';
	dialog+='<a href="javascript:void(0);" id="ConfirmDialog_NO" onclick="BlackDiv_close(true);"></a>';
	dialog+='';
	dialog+='</div>';
	dialog+='<div class="clear"></div>';
	dialog+='';
	dialog+='</div>';
	$("#OverBlackDiv").prepend(dialog);
	$("#ConfirmDialog_YES").click(function()
	{
		BlackDiv_close(true);
		eval( paramCallback );
	});
	OverBlackDiv_reposition();
}

function document_dimentions()
{
	DocumentHeight = $(document).height();
	DocumentWidth = $(document).width();
	VisibleHeight = window.innerHeight || document.body.clientHeight;
	VisibleWidth = window.innerWidth || document.body.clientWidth;
}

function input_check_only_numbers( paramID )
{
	var chk = /[^0-9]/g;
	if (chk.exec ( $("#"+paramID).val() ) )
	{ 
		$("#"+paramID).val( $("#"+paramID).val().replace( chk, "" ) );
		$("#"+paramID).focus();
		return false;
	}
	return true;
}

function showLoginDialog()
{
	BlackDiv();
	var dialog = '<div id="LoginDialog" class="center_center">';
	dialog+='<iframe src="'+baseurl+'login/" frameborder="0" ';
	dialog+=' marginwidth="0"';
	dialog+=' marginheight="0"';
	dialog+=' width="350"';
	dialog+=' height="200"';
	dialog+=' scrolling="no">';
	dialog+='</iframe>';
	dialog+='</div>';
	$("#OverBlackDiv").prepend(dialog);
	$("#ConfirmDialog_YES").click(function()
	{
		BlackDiv_close(true);
		eval( paramCallback );
	});
	OverBlackDiv_reposition();
}

function PreviewProjectPage( paramPage )
{// 
	paramPage = paramPage || 0;
	var total = $("#SlideFrame #Slide .Block").length - 1;
	var current = 1;
	$("#SlideFrame #Slide .Block").each(function(i)
	{
		if( $(this).css("display") == "block" )
		{
			current = i;
		}
	});
	if( paramPage < 0 )
	{// back
		//alert(" : "+(current - 1));
		if( (current - 1) >= 0 )
		{
			current = current - 1;
		}
	}
	else
	{
		if( (current + 1) <= total )
		{
			current = current + 1;
		}
	}
	$("#SlideFrame #Slide .Block").css("display", "none");
	$("#SlideFrame #Slide .Block:eq("+current+")").css("display", "block");
	project_view_refit_slide(current);
}

function project_view_refit_slide( paramBlock )
{
	var set_height = $("#SlideFrame #Slide .Block:eq("+paramBlock+") img").height();
	var new_height = 0;
	var has_title = false;
	var has_description = false;
	var title_height = $("#SlideFrame #Slide .Block:eq("+paramBlock+") .Img .Text .PictureTitle").height();
	var text_height = $("#SlideFrame #Slide .Block:eq("+paramBlock+") .Img .Text .PictureText").height();
	$("#SlideFrame").attr("style", "height:"+set_height + "px");
	$("#Slide").attr("style", "height:"+set_height + "px");
	new_height = set_height;
	if( typeof title_height == "number" )
	{
		new_height = set_height + title_height;
		has_title = true;
	}
	if( typeof text_height == "number" )
	{
		new_height = set_height + text_height;
		has_description = true;
	}
	
	$("#SlideFrame #Slide .Block").css("width","542px");
	$("#SlideFrame #Slide .Block:eq("+paramBlock+")").css("width","540px");
	$("#SlideFrame #Slide .Block:eq("+paramBlock+")").attr("style","height:"+set_height+"px");
	$("#SlideFrame #Slide .Block:eq("+paramBlock+") img").attr("style","height:"+set_height+"px");
	$("#SlideConteiner").animate(
	{
		"height" : (set_height+5)+"px"
	},"fast");
}

function projects_view()
{
	$("#SlideFrame #Slide .Block").css("display", "none");
	$("#SlideFrame #Slide .Block:eq(0)").css("display", "block");
	$("#ProjectView #SlideConteiner #SlideFrame #Slide .Block .Img .Text").fadeTo(1,"0.5" );
	$("#SlideFrame #Slide .Block .Img .Text").hover(function()
	{
		var title_height = $(this).find(".PictureTitle").height();
		var text_height = $(this).find(".PictureText").height();
		var sum_height = title_height + text_height;
		if( sum_height > 33 )
		{
			$(this).animate(
			{
				"height" : sum_height + "px"
			},"fast");
			$(this).fadeTo("fast", "1" );
		}
	},function()
	{
		$(this).animate(
		{
			"height" :  "33px"
		},"fast");
		$(this).fadeTo("fast", "0.5" );
	});
	project_view_refit_slide(0);
}

function showSharePanel()
{
	var current_state = $("#ViewSharePanel").css("display");
	if( current_state == "none")
	{
		$("#ViewSharePanel").slideDown("fast", function()
		{
			$(this).css("display", "block");	
		});	
	}
	else
	{
		$("#ViewSharePanel").slideUp("fast", function()
		{
			$(this).css("display", "none");	
		});
	}
}

function share_facebook()
{
	var title = document.title;
	var url = window.location;
	window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(url)+'&t='+encodeURIComponent(title),'sharer','toolbar=0,status=0,width=626,height=436');
}

function share_myspace()
{
	var title = document.title;
	var url = window.location;
	var description = $("meta[name*=description]").attr("content");
	window.open( 'http://www.myspace.com/Modules/PostTo/Pages/?u='+encodeURIComponent(url)+'&t='+encodeURIComponent(title)+'&c='+encodeURIComponent(description),'sharer','toolbar=0,status=0,width=626,height=436');
}

function share_twitter()
{
	var title = document.title;
	var url = window.location;
	window.open('http://twitter.com/home?status=' + encodeURIComponent(url + " " + title), 'sharer','toolbar=0,status=0,width=800,height=436');
}

function share_googlebuzz()
{
	var url = window.location;
	var image = $("link[rel*=image_src]").attr('href');
	window.open('http://www.google.com/buzz/post?url=' + encodeURIComponent(url)+"&imageurl="+image, 'sharer','toolbar=0,status=0,width=800,height=436');
}