$().ready(function(){
	init();
})

function dialogPopup(options){
	$("#" + options.id).dialog("open");
	$("#" + options.id).dialog("option", "title", options.title);
	if (options.src != null){
		$("#" + options.modalIFrameID).attr("src", options.src);
	}
}

function isW3C(){
	return $.support.cssFloat;
}

function modalW3C (isW3C){
	var modalW3C = "<div id='modalDialog' title='Dialog Title'>";
		modalW3C += "<iframe id='modal_iframe' width='100%' height='100%' frameborder='0' src='http://wwww.ipreo.com/accessibility.asp'></iframe></div>";
	
	var modalIE = "<div id='modalDialog' title='Dialog Title'>";
		modalIE += "<iframe id='modal_iframe' width='100%' height='100%' scrolling='yes' horizontalscrolling='no'";
		modalIE += "verticalscrolling='yes' frameborder='0' src='http://wwww.ipreo.com/accessibility.asp'></iframe></div>";

	var modal = "";
		
	return modal = isW3C ? modalW3C : modalIE;
}

function loadModals(){
	
	isW3C() ? $("#wrapper").append(modalW3C(true)) : $("#wrapper").append(modalW3C(false));
	
	$("#modalDialog").dialog({
		autoOpen: false,
		width: 800,
		height: 500,
		modal: true,
		buttons: {
			"Close": function(){
				$(this).dialog("close");
			}
		}
	});
}

function treeAction(_this) {
	_this.parent().siblings().children(".local_nav_sub_nav:visible").jQSliderToggle( {
		speed : 400
	});
	_this.parent().siblings().children(".siteMapNoLink").addClass("expandable").removeClass("collapsible");
	
	_this.hasClass("expandable") ? _this.addClass("collapsible").removeClass("expandable") : _this.addClass("expandable").removeClass("collapsible");
	_this.siblings().stop().jQSliderToggle( {
		speed : 400
	});


}

function init(){
	
	$(".bluesquare docs li a").click(function(e){
		e.stopPropagation();
	})


	$("#legal li a.modal_link").click(function(e){
		var title = $(this).attr("title");
		var src = $(this).attr("href");
		
		dialogPopup({title: title, 
					src : src, 
					id : "modalDialog", 
					modalIFrameID: "modal_iframe"});
		
		e.preventDefault();
	})
	
	$(".expandable, .collapsible").click(function(e){
		treeAction($(this));
		e.preventDefault();
	})
	
	loadModals();
}
