var ajaxQS = '&ajax=true';

function resize_full_image(customWidth)
{
	var objImg		= document.getElementById('img_full');
	var imgRatio	= objImg.width / objImg.height;
	var maxWidth	= (typeof customWidth !== 'number') ? 974 : parseInt(customWidth);

	if(objImg.width > maxWidth)
	{
		objImg.width	= maxWidth;
		objImg.height	= maxWidth / imgRatio;
	}
}

function ratingSubmit(value, form)
{
	$('#rating_form .progress').removeClass('hide');

	$.ajax({
		url: $(form).attr('action'),
		data: $(form).serialize() + ajaxQS,
		error: ratingError,
		success: ratingSuccess
	});
	
	$('.rate', form).rating('disable');
}

function ratingSuccess(response)
{
	$('#rating_msg').html(response.text);
	$('#rating_form .progress').addClass('hide');
}

function ratingError(XMLHttpRequest, textStatus, errorThrown)
{
	$('#rating_msg').html('Error while rating.');
	$('#rating_form .progress').addClass('hide');
}

$.ajaxSetup({ type: 'POST', data: ({ ajax: 'true' }), dataType: 'json' });

$(document).ready(function(){

	// Hide & Disable certain elements
	$('#login_form').hide();
	$('a.disabled').click(function(){ return false; });
	
	if($().tabs)
	{
		// Enabling tabbed div's
		$('.tabbed').tabs({ fx: { opacity: 'toggle' } }).find('h4').hide();
		
		// Auto-rotate first tab group.
		$('.tabbed:first').tabs('rotate', 3000)
		
		// Fix for page-jumps when a tab auto-rotates
		$('.tabbed').css('height', function(){ return $(this).css('height')});
	}
	
	// Fading in/out image on mouseover
	$('.img_list img').hover(
		function(){ $(this).fadeTo('fast', 0.8); },
		function(){ $(this).fadeTo('fast', 1); }
	);
	
	if($().rating)
	{
		// AJAX Ratings Enable
		$('.rating .rate').rating({
			required: 'true',
			callback: function(value, link){ ratingSubmit(value, this.form); }
		});
	}
	
	// Modal Register & Login boxes
	$('.modal_login').click(function(){ modalLogin(); return false; });
	
});

function modalLogin()
{
	Boxy.load('http://forums.indialot.com/login.html', {cache:true, modal:true, unloadOnHide:true});
}