$(document).ready(function(){
	$('a.fancy').fancybox({
		'showCloseButton'	: true,
		'titlePosition' 	: 'inside',
		'titleFormat'		: formatTitle,
		'titleFromAlt'		:true 
	});
	function formatTitle(title, currentArray, currentIndex, currentOpts) {
		var tmp = title.split("::");
		var html = "";
		if(tmp.length>0){
			html = "<div id='tip7-title'>";	
				//TITLE
					if(tmp[0] && tmp[0]!=""){
						html+= "<strong>"+tmp[0]+"</strong><br />";	
					}
				//DESCRIPTION
					if(tmp[1] && tmp[1]!=""){
						html+= tmp[1];	
					}
					html+= "<div class='hr'></div>";
				//START DATE
					if(tmp[2] && tmp[2]!=""){
						html+= "<div style='float:left;width:225px;text-align:left;'><strong>Start Date: </strong>"+tmp[2]+"</div>";	
					}
				//COMPLETE DATE
					if(tmp[3] && tmp[3]!=""){
						html+= "<div style='float:left;width:225px;text-align:left;'><strong>Completion Date: </strong>"+tmp[3]+"</div>";	
					}
				//PROJECT SIZE
					if(tmp[4] && tmp[4]!=""){
						html+= "<div style='float:left;width:225px;text-align:left;'><strong>Size: </strong>"+tmp[4]+"</div>";	
					}
				//PROJECT LOCATION
					if(tmp[5] && tmp[5]!=""){
						html+= "<div style='float:left;width:225px;text-align:left;'><strong>Location: </strong>"+tmp[5]+"</div>";	
					}
				//PROJECT PRICE
					if(tmp[6] && tmp[6]!=""){
						html+= "<div style='float:left;width:225px;text-align:left;'><strong>Price: </strong>"+tmp[6]+"</div>";	
					}
				//PROJECT OWNER INFO
					if(tmp[7] && tmp[7]!=""){
						html+= "<div style='float:left;width:225px;text-align:left;'><strong>Owner Info: </strong>"+tmp[7]+"</div>";	
					}
				//DESIGN TEAM
					if(tmp[8] && tmp[8]!=""){
						html+= "<div style='float:left;width:225px;text-align:left;'><strong>Design Team: </strong>"+tmp[8]+"</div>";	
					}
				//PROJECT RESPONSIBILITIES
					if(tmp[9] && tmp[9]!=""){
						html+= "<div style='float:left;width:225px;text-align:left;'><strong>Project Responsibilities: </strong>"+tmp[9]+"</div>";	
					}
				//
					if(tmp.length>2){
						html+= "<br clear='all' />";
					}
				//
					html+= "<div style='float:right;'>";
					if(tmp[10] && tmp[10]!=""){
						html+= "<a href='"+tmp[10]+"' target='_blank'><strong>Project Sheet</strong></a> | ";
					}
					html+= "Image " + (currentIndex + 1) + " of " + currentArray.length + "</div><br clear='all' /></div>";	
		}
		return html;
		//return '<div id="tip7-title">' + (title && title.length ? '<strong>' + tmp[0] + '</strong><br/>' + tmp[1] : '' ) + '<br /><br />Image ' + (currentIndex + 1) + ' of ' + currentArray.length + '</div>';
	}
	/*
	 * MENU
	 */
	$('body').click(function(event) {
		if (!$(event.target).closest('#port').length && !$(event.target).closest('#fancybox-wrap').length && !$(event.target).closest('#fancybox-overlay').length) {
			$("#port ul").find("ul").css({
				"display":"none"
			});
			$("#port ul").find("a.active").removeClass("active");
		};
	});
	$("#port a").click(function(){
		//HIDE ANY OPEN MENUS
			$(this).parent().parent().find("ul").css({
				"display":"none"
			});
		//HIDE ANY OF ITS SIBLINGS (FOR ROOT MENU)
			$(this).parent().parent().siblings().find("ul").css({
				"display":"none"
			});
		//REMOVE ACTIVE CLASS
			$(this).parent().siblings().find("a.active").removeClass("active");
		//REMOVE ACTIVE CLASS (FOR ROOT MENU)
			$(this).parent().parent().siblings().find("a.active").removeClass("active");
		//ADD ACTIVE TO OUR LINK THAT WAS CLICKED
			$(this).addClass("active");
		//SHOW THE NEXT MENU (THE NEXT UL)
			$(this).next().css({
				"display":"block"
			}).addClass("active");
	});
	/*
	 *	PORTFOLIO MORE INFO CLOSE BUTTON
	 */
	/*$("#port_info_close").click(function(){
		$("#port_info_content").html("");
		$(this).parent().css({
			"display":"none"
		});
	});*/
});
/*
 * 	LOAD THE PROJECT DETAILS AND IMAGES
 */
/*function load_project(project_id){
	$("#port_info_content").html("");
	$("#port_info_box").css({
		"display":"block"
	});
	$("#port_info_loading").css({
		"display":"block"
	});
	$.ajax({
		url:"http://dev.werkbot.com/rectenwald/wp-admin/admin-ajax.php",
		type:'POST',
		dataType: 'json',
		data:'action=load_project&project_id='+project_id,
		success:function(results){
			$("#port_info_loading").css({
				"display":"none"
			});
			$("#port_info_content").html(results[0]);
			$("#port_gallery_rotate").botrotate({
				'time': '10',
				'element': 'img',
				'buttons': true,
				'button_type' : 'NEXTPREV',
				'ease_in': 'easeInQuad',
				'ease_out': 'easeOutQuad',
				'ease_speed': 1,
				'transition': 'FADE',
				'center': true
			});
		}
	});
}*/
