$(document).ready(function(){
	load_settings_sub();
	input_rel();
	init_abuse();
	noCache();
	var g_obj;
});
function init_abuse(){
		$("#report_dialog").dialog({
			bgiframe: true,
			autoOpen: false,
			modal: true,
			width: 310,
			position: ['center',220],
			buttons: {
				Send: function() {
						$.ajax({
						   type: "POST",
						   url: '/functions/abuse.asp',
						   data: g_obj.attr('rel') + '&reason=' + Url.encode($('#reason').val()),
							 beforeSend: function(){
								 g_obj.html('<img src="/_images/default_skin/loading_18.gif">');
							   },
							 success: function(){g_obj.fadeOut(); }	
						 });
					$(this).dialog('close');			
				},
				Cancel: function() {
					$(this).dialog('close');
				}
			},
			close: function() {
			}
		});

	$('.report_abuse').click(function(){
		g_obj = $(this);
		$("#report_dialog").dialog('open');
		}
	);
}

var mousetimer;
function load_settings_sub() {
	$("#topnav #topnav_settings #sub a").hover(function () {
		  $(this).css({'background-color' : '#C4E1FF'});
		}, function () {
		  var cssObj = {'background-color' : ''};
		  $(this).css(cssObj);
		});
	$('#topnav #topnav_settings #slink').toggle( function(){
		$("#topnav #topnav_settings #sub").animate({ 
			height: 'show', 
			opacity: 'show' 
			}, 'slow'); 
			$(document).click(function(){
				$('#topnav #topnav_settings #slink').trigger('click');
			})		
			$("#topnav #topnav_settings #sub").mouseleave(function(){
				mousetimer = setTimeout("$('#topnav #topnav_settings #slink').trigger('click');",1200)
				$("#topnav #topnav_settings #sub").unbind('mouseleave');
			});
		}, function(){
			clearTimeout(mousetimer);
			$("#topnav #topnav_settings #sub").animate({ 
				height: 'hide', 
				opacity: 'hide' 
				}, 'slow'); 
				$(document).unbind('click');
				$("#topnav #topnav_settings #sub").mouseenter(function(){
					clearTimeout(mousetimer);
				});
		} );
}
function input_rel(){
	$('textarea').focus(function() {
		if ($(this).val()==''|| $(this).val()==$(this).attr('rel'))
		{
			$(this).val('');
			$(this).css('color','');
		}
	});
	$('textarea').blur(function() {
		if ($(this).val()=='')
		{
			$(this).val($(this).attr('rel'));
			$(this).css('color','gray');
		}
	});
	$('textarea').trigger("blur");
	$('textarea.grow').elastic();
}

function noCache(){
	$('img.nocache').one('load',function(){
			var operator = '';
			if($(this).attr('src').indexOf('?')>0){operator='&'}else{operator='?'};
			$(this).attr('src',$(this).attr('src')+operator+'nocache=' + Math.random()*9999999);
	});
}
