$(document).ready(function() {
	//$('div.roundbox').corner('round bottom 9px');
	//$('div.roundboxtop').corner('round top 9px');

})

var mainGridView = new Array();

function selRow(gridViewIndex, row, key) {
	// mainGridView var is set in asp.net code in AdminMasterListControl.cs
	//__doPostBack(mainGridView[gridViewIndex], 'Select$' + row);
	if (key != null && key.toString().length > 0)
		__doPostBack(mainGridView[gridViewIndex], 'SelectKey$' + key);
	else
		__doPostBack(mainGridView[gridViewIndex], 'Select$' + row);
}

var initFunctions = new Array();

function pageLoadedHandler() {
	$('.textinput').focus(function() {
		$(this).attr('class', 'textinputHovered');
	});

	$('.textinput').blur(function() {
		$(this).attr('class', 'textinput');
	});

	$('.textarea').focus(function() {
		$(this).attr('class', 'textareaHovered');
	});

	$('.textarea').blur(function() {
		$(this).attr('class', 'textarea');
	});

	$('.textinputSmall').focus(function() {
		$(this).attr('class', 'textinputSmallHovered');
	});

	$('.textinputSmall').blur(function() {
		$(this).attr('class', 'textinputSmall');
	});

	$('input[type=text], input[type=password], textarea').focus(function() {
		$(this).addClass('Hover');
	});

	$('input[type=text], input[type=password], textarea').blur(function() {
		$(this).removeClass('Hover');
	});

	for (i = 0; i < initFunctions.length; i++) {
		initFunctions[i]();
	}

	$('.CollapseUI').click(collapse);
	$('.ExpandUI').click(expand);

	$('.LeftPanel').add('.TopPanel').dblclick(collapse);
	$('.MainContent').dblclick(expand);

	$('.HeaderLogo').hover(function () {
		$(this).addClass('Hover');
	}, function () {
		$(this).removeClass('Hover');
	});

	var expanded = true;

	function collapse() {
		if (expanded) {
			finished = 0;
			increase = function() { finished++; if (finished == 3) expanded = false; }; // Make sure we finished all animation before enabling toggling again.  (to avoid certain UI problems)
			$('.HeaderCorner').hide();
			$('.LeftPanel').animate({ left: "-187px" }, "slow", increase);
			$('.TopPanel').add('.HeaderLogoHover').animate({ top: -$('.TopPanel').height() }, "slow", increase);
			$('.MainContent').css({ position: "relative" });
			$('.MainContent').animate({ marginLeft: '0px', top: -$('.TopPanel').height() }, "slow", increase);

			$('.HeaderLogo').fadeOut('slow');

			$('.CollapseUI').hide();
			$('.ExpandUI').fadeIn('slow');

			//FranchiseBlast.WebServices.Various.CollapseUI(true);
		}
	}

	function expand() {
		if (!expanded) {
			$('.MainContent').animate({ marginLeft: '187px', top: "0px" }, "slow", function() { $(this).css({ position: "" }); });
			$('.TopPanel').add('.HeaderLogoHover').animate({ top: '0px' }, "slow", function() { $('.HeaderCorner').fadeIn('slow'); });
			$('.LeftPanel').animate({ left: "0px" }, "slow");

			$('.HeaderLogo').fadeIn('slow');

			$('.CollapseUI').fadeIn('slow');
			$('.ExpandUI').hide();

			setTimeout(function() { expanded = true; }, 200);
			//FranchiseBlast.WebServices.Various.CollapseUI(false);
		}
	}
}
