$(document).ready(function() {
	var isSliding = false;
	
	function setIsSliding(val) {
		isSliding = val;		
	}

	$("li.nav-itm").hover(function() {
		isSliding = true;
		$('.sub-menu-cont', this).stop();
		$('.sub-menu-cont', this).css({'display':'block','overflow':'hidden'});
		$('.sub-menu-cont', this).animate({
			height:$('.sub-menu-cont ul', this).height()
		},{
			duration:200
		})
	}, function() {
		isSliding = true;
		$('.sub-menu-cont', this).stop();
		$('.sub-menu-cont', this).animate({
			height:0
		},{
			duration:200,
			complete:function(){
				$(this).css({'display':'none'})
			}
		})
	});
	

	function openAccordion(fragment){
		var indice;		
		$('.accordionListTitle').each(function(index) {
		  	if(this.id==fragment){
		  		indice = index;
		  	}
		});
		$('#accordionList').accordion("activate", indice);
	}
	
	$('#accordionList').accordion({
		autoHeight : false,
		active : -1,
		collapsible : true,
		change : function(e) {
			var index = $('#accordionList').accordion('option', 'active');
			var el = $('.accordionListTitle').get(index);
			if(index!==false){			
				$('html,body').animate({ 
					scrollTop : $(el).offset().top
				}, 'slow');
			}				
		}
	});
	
	var hash = $.param.fragment();
	if(hash && hash != "") {
		openAccordion(hash);
	}	
	
	$(window).bind('hashchange', function(event) {
		openAccordion(event.fragment);
	});

});


function openDialog(title, text) {

	$('body').append(
			'<div id="dialog-message" title="' + title + '">' + '<p>'
					+ '<span class="ui-icon ui-icon-circle-check" style="float:left; margin:0 7px 50px 0;"></span>' + text + '</p>' + '</div>');

	$("#dialog:ui-dialog").dialog("destroy");

	$("#dialog-message").dialog({
		modal : true,
		buttons : {
			Ok : function() {
				$(this).dialog("close");
			}
		}
	});

}

$.fn.serializeObject = function() {
	var o = {};
	var a = this.serializeArray();
	$.each(a, function() {
		if (o[this.name]) {
			if (!o[this.name].push) {
				o[this.name] = [ o[this.name] ];
			}
			o[this.name].push(this.value || '');
		} else {
			o[this.name] = this.value || '';
		}
	});
	return o;
};

function MM_openBrWindow(theURL, winName, features, dimension) { // v2.0
	if (dimension != null) {
		theURL += '&width=' + screen.width + '&height=' + screen.height;
	}
	window.open(theURL, winName, features);
}

function open_form(theURL, winName, features) { // v2.0
	window.open(theURL, winName, features);
}
