// strategy = 0 - simple modeal is turned off
// strategy = 1 - checking the url
// strategy = 2 - checking the random value
var simplemodal_strategy = 0;
var simplemodal_url = '/VehiclesAuctions/results';
var simplemodal_random_value = 0.2;

/*
$(document).ready(function(){
	if($.cookie('username') != '') {
		$("#username").val($.cookie('username'));
//		$("#RememberMe").val(1);
//		$("#RememberMe").attr('checked', 'checked');
	}
//	if($.cookie('password')) {
//		$("#password").val($.cookie('password'));
//	}
	
	$("#lform").submit(function() {
//		alert($("#username").val());
//		alert($("#RememberMe").attr('checked'));
		
		if($("#RememberMe").attr('checked') == true) {
//			alert('checked == true: username = '+$("#username").val());
			$.cookie('username', $("#username").val(), {expires: 30, path: '/', domain: location.host});
//			$.cookie('password', $("#password").val(), {expires: 30, path: '/', domain: location.host});
//			alert($.cookie('password'));
		} else {
//			alert('checked == false: username = '+$("#username").val());
			$.cookie('username', null);
		}
	});
});
*/

function showForm(formName) {
//	alert('formName = '+formName);
	var allforms=document.getElementsByTagName("form");
	for(var i=0;i<allforms.length;i++) {
		allforms[i].parentNode.parentNode.style.display = "none";
	}
	document.getElementById(formName).style.display = "block";
//	alert(document.getElementById(formName).className);
}


function switchVisibility(e, type) {
//	e.src
//	alert('type = '+type);
//	alert('display = '+document.getElementById(type).style.display);
	var div = document.getElementById(type);
	if(div.style.display == 'block') {
		e.src = e.src.replace('Opened', 'Closed');
		e.alt = 'Open List';
		div.style.display = 'none'
	} else {
		e.src = e.src.replace('Closed', 'Opened');
		e.alt = 'Close List';
		div.style.display = 'block'
	}
//	alert(e.src);
}

var ebookdir = '';

$(document).ready(function(){
	$('#spotlights').cycle({ 
		fx:    'fade', 
		speed:  500,
		timeout:  4500
//		fx: 'scrollDown',
//		speedIn:  2000,
//		speedOut: 500,
//		easeIn:  'bounceout',
//		easeOut: 'backin',
//		delay:   -5000
		});
		
	$("#tree").treeview({
		collapsed: true,
		animated: "medium",
		control:"#sidetreecontrol",
		prerendered: true,
		persist: "location"
		});
		
	$('.ebookBody').each(function() {
		ebookdir = 'ebook';
		$.ajax({
				type: 'GET',
				url: '/ebook/Introduction_1.html',
				success: function(data) {
					$('<div id="Introduction_1">'+data+'</div>').prependTo('#contentMain');
				}
		});	
	});

	$('.tanantbookBody').each(function() {
		ebookdir = 'tenant_ebook';
		$.ajax({
				type: 'GET',
				url: '/tenant_ebook/01_Introduction.html',
				success: function(data) {
					$('<div id="01_Introduction">'+data+'</div>').prependTo('#contentMain');
				}
		});	
	});
	
	$('#tree a').click(function() {
//		alert(this.hash);
		
		$('#contentMain div').hide();
		if(!$(this.hash).length) {
			var id = this.hash.substring(1);
			$.ajax({
					type: 'GET',
					url: '/'+ebookdir+'/'+id+'.html',
					success: function(data) {
						$('<div id="'+id+'">'+data+'</div>').prependTo('#contentMain');
					}
			});	
		} else {
			$(this.hash).show();
		}
		
		return false;
	});
	

	if((simplemodal_strategy == 1 && simplemodal_url == document.location.pathname) || (simplemodal_strategy == 2 && simplemodal_random_value <= Math.random())) {
		$(document).mousemove(function(e) {
			if($('html').attr('scrollTop')) {
				var offset = e.pageY - $('html').attr('scrollTop');
			} else if($('body').attr('scrollTop')) {
				var offset = e.pageY - $('body').attr('scrollTop');
			} else {
				var offset = e.pageY;
			}
		
			if(offset <= 5) {
				$('#exit_content').modal({onOpen: modalOpen, onClose: simplemodal_close});
			}
		}); 
	}


});

/**
 * When the open event is called, this function will be used to 'open'
 * the overlay, container and data portions of the modal dialog.
 *
 * onOpen callbacks need to handle 'opening' the overlay, container
 * and data.
 */
function modalOpen (dialog) {
 dialog.overlay.fadeIn('fast', function () {
 dialog.container.fadeIn('fast', function () {
 dialog.data.hide().slideDown('fast');
 });
 });
}

 /**
 * When the close event is called, this function will be used to 'close'
 * the overlay, container and data portions of the modal dialog.
 *
 * The SimpleModal close function will still perform some actions that
 * don't need to be handled here.
 *
 * onClose callbacks need to handle 'closing' the overlay, container
 * and data.
 */
function simplemodal_close (dialog) {
 dialog.data.fadeOut('fast', function () {
 dialog.container.hide('fast', function () {
 dialog.overlay.slideUp('fast', function () {
 $.modal.close();
 });
 });
 });
}


function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

