function jReport(id) {
	//"../index.php?act=comment&mode=report&cid=" + id;
	$('#comreport').dialog('open');
	return false;
}

function jEmail() {
	var to = escape(document.getElementById("email").value);
	$('#comemail').dialog('open');
	
	$.ajax({
	  url: "../index.php?act=user&mode=email&wid=" + wid + "&recipient=" + to,
	  success: function(data) {
		$('#email1').css("display", "none");
		$('#email2').css("display", "inline");
	  }
	});

	return false;

}

$(document).ready(function(){
	
	$("ul.topnav li a").hover(function() {
		
		$(this).parent().find("ul.subnav").slideDown('fast').show();

		$(this).parent().hover(function() {
		}, function(){	
			$(this).parent().find("ul.subnav").slideUp('slow');
		});

		}).hover(function() { 
			$(this).addClass("subhover");
		}, function(){
			$(this).removeClass("subhover");
	});

	$('div.img2 a').hover(function() {
		$(this).parent().find("div.caption").slideDown('fast').show();

		$(this).parent().hover(function() {
		}, function(){	
			$(this).parent().find("div.caption").slideUp('slow');
		});

	});

	// Submenu
	var src;
	var base;

	src = $('#sub2').attr('src');
	base = src.substr( 0, src.lastIndexOf('/') + 1 );

	$('#sub5').hover(function() { 
		if($('#sub5').attr('src') == base + 'contact1.png') {
			$('#sub5').attr('src', base + 'contact2.png');
		} else {
			$('#sub5').attr('src', base + 'contact1.png');
		}
	});

	$('#sub4').hover(function() { 
		if($('#sub4').attr('src') == base + 'search.png') {
			$('#sub4').attr('src', base + 'search2.png');
		} else {
			$('#sub4').attr('src', base + 'search.png');
		}
	});

	$('#sub3').hover(function() { 
		if($('#sub3').attr('src') == base + 'wallpapers1.png') {
			$('#sub3').attr('src', base + 'wallpapers2.png');
		} else {
			$('#sub3').attr('src', base + 'wallpapers1.png');
		}
	});

	$('#sub2').hover(function() { 
		if($('#sub2').attr('src') == base + 'account1.png') {
			$('#sub2').attr('src', base + 'account2.png');
		} else {
			$('#sub2').attr('src', base + 'account1.png');
		}
	});

	$('#sub1').hover(function() { 
		if($('#sub1').attr('src') == base + 'home.png') {
			$('#sub1').attr('src', base + 'home1.png');
		} else {
			$('#sub1').attr('src', base + 'home.png');
		}
	});


});

$(function(){
	
	// Dialog			
	$('#comdialog').dialog({
		autoOpen: false,
		width: 350,
		title: "Add comment",
		modal: true,
		resizable: false,
		closeOnEscape: false,
		buttons: {
			"Ok": function() {
				if(document.getElementById("success").style.display == "inline") {
					document.getElementById("step1").style.display = "inline";
					document.getElementById("step2").style.display = "none";
					document.getElementById("success").style.display = "none";
					document.getElementById("failure").style.display = "none";
					$(this).dialog("close");
					return;
				}
				document.getElementById("success").style.display = "none";
				document.getElementById("failure").style.display = "none";

				$.ajax({
				  url: '../index.php?act=comment&c=' + escape(document.getElementById("textComment").value) + '&wid=' + wid + '&reply=' + reply,
				  success: function(data) {
					document.getElementById("step2").style.display = "none";
					if(data.indexOf("Inserted comment") == 0) {
					document.getElementById("success").style.display = "inline";
						FinishedComment();
					return;
					} else {
					document.getElementById("failmsg").innerHTML = data + "<br /><a href='#' onclick='document.getElementById(\"failure\").style.display = \"none\"; document.getElementById(\"step1\").style.display = \"inline\"; return false;' style='color: #F56E00;'><small>New comment</small></a>";
					document.getElementById("failure").style.display = "inline";
					return;
					}
					
				  }
				});
				document.getElementById("step1").style.display = "none";
				document.getElementById("step2").style.display = "inline";
			}, 
			"Cancel": function() { 
				$(this).dialog("close"); 
				document.getElementById("step1").style.display = "inline";
				document.getElementById("step2").style.display = "none";
				document.getElementById("success").style.display = "none";
				document.getElementById("failure").style.display = "none";
				
			} 
		}
	});

	$('#dialog_link').click(function(){
		$('#comdialog').dialog('open');
		return false;
	});

	
	// Dialog			
	$('#comreport').dialog({
		autoOpen: false,
		width: 350,
		title: "Report",
		modal: true,
		resizable: false,
		closeOnEscape: false,
		buttons: {
			"Ok": function() {
				$(this).dialog("close");
			}, 
		}
	});

	$('#comemail').dialog({
		autoOpen: false,
		width: 350,
		title: "Email Wallpaper",
		modal: true,
		resizable: false,
		closeOnEscape: false,
		buttons: {
			"Ok": function() {
				$(this).dialog("close");
				$('#email1').css("display", "inline");
				$('#email2').css("display", "none");
			}, 
		}
	});




});
