//preloading images
var preloading_1 = new Image();
preloading_1.src = "/images/loading-small.gif";
var preloading_2 = new Image();
preloading_2.src = "/images/loading.gif";

$(document).ready(function() {
	if (jQuery.browser.msie && jQuery.browser.version < 7){
		var height = $(window).height();
		height = height - 127 + 'px';
		$('#contentWindow').css("height", height);
		$('#contentLayer').css("height", height);
	}
});
if (jQuery.browser.msie && jQuery.browser.version < 7){
	$(window).resize(function() {
		var height = $(window).height();
		height = height - 127 + 'px';
		$('#contentWindow').css("height", height);
		$('#contentLayer').css("height", height);
	});
}
var user = {
	login:function(contentWindow, formId, small){
		ajax.postForm(contentWindow, formId, small, '/account/login/verify/');
	},
	logout:function(contentWindow, small){
		ajax.doRequest(contentWindow, small, '/account/login/logout/');
	}
}

var album = {
	showPicture:function(photo){
		$('#photoFrameBg').fadeIn("slow");
		$('#photoFrame').fadeIn("slow");
		$('#photo').attr('src', photo);
	},
	hidePicture:function(){
		$('#photoFrameBg').fadeOut("slow");
		$('#photoFrame').fadeOut("slow");
	}
}
var ajax = {
	setLoader:function(elementId, small){
		if (small){
			$('#'+elementId).html('<div class="centerLoader"><img src="/images/loading-small.gif"></div>');
		}else{
			$('#'+elementId).html('<div class="centerLoader"><img src="/images/loading.gif"></div>');
		}
	},
	postForm:function(contentWindow, formId, small, postUrl){
		$.ajax({
			type: "POST",
			url: postUrl,
			data: $('#'+formId).serialize(),
			beforeSend : ajax.setLoader(contentWindow, small), 
			success : function(data, textStatus){
				$('#'+contentWindow).html(data);
			}
		});
	},
	doRequest:function(contentWindow, small, postUrl){	
		$.ajax({
			type: 'GET',
			url: postUrl,
			beforeSend : ajax.setLoader(contentWindow, small),
			success : function(data, textStatus){
				$('#'+contentWindow).html(data);
			}
		});
	}
}

function initMenus() {
	$('ul.menu ul').hide();
	$.each($('ul.menu'), function(){
		$('#' + this.id + '.expandfirst ul:first').show();
	});
	$('ul.menu li a').click(
		function() {
			var checkElement = $(this).next();
			var parent = this.parentNode.parentNode.id;

			if($('#' + parent).hasClass('noaccordion')) {
				$(this).next().slideToggle('normal');
				return false;
			}
			if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
				if($('#' + parent).hasClass('collapsible')) {
					$('#' + parent + ' ul:visible').slideUp('normal');
				}
				return false;
			}
			if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
				$('#' + parent + ' ul:visible').slideUp('normal');
				checkElement.slideDown('normal');
				return false;
			}
		}
	);
}