
/*-------------------------------------------
	COPROTATE SEARCH */
	
var corporateSearch = function() {
	window.location.href = "/search/search.aspx?searchTerm=" + $("#searchDiakon").val();
}

/*-------------------------------------------
	jQuery ACCORDION PANELS */
	
var jQueryAccordion = function() {
	$("#accordionPanels").find("div").each(function() {
		$(this).css("display", "none");
		$(this).prev().addClass("inactive");							   
	});
	
	$("#accordionPanels div:first").prev().removeClass("inactive");
	$("#accordionPanels div:first").prev().addClass("active");
	$("#accordionPanels div:first").prev().attr("id", "active");
	$("#accordionPanels div:first").slideDown("slow");
	
	// Removes odd margin below div/img in the accordion.
	$("#accordionPanels div").find("img").each(function() {
		$(this).wrap("<div></div>");
		//$(this).remove();
	});

	$("#accordionPanels a").click(function(event) {
								  
		$("#accordionPanels").find("a").each(function() {
			$(this).removeAttr("id");
			$(this).removeClass("active");
		});
		
		var clicked = $(this);
		clicked.attr("id", "active");
		clicked.blur();
		
		$("#accordionPanels").find("div").each(function() {
			if ($(this).prev().attr("id") == clicked.attr("id")) {
				if (clicked.next().css("display") !== "block") {
					clicked.removeClass("inactive");
					clicked.addClass("active");
					clicked.next().slideDown("slow");
				} else {
					clicked.removeClass("active");
					clicked.addClass("inactive");
					clicked.next().slideUp("slow");
				}
			} else {
				$(this).prev().removeClass("active");
				$(this).prev().addClass("inactive");
				$(this).slideUp("slow");
			}
		});
		return false;
	});
}

/*-------------------------------------------
	jQuery TABBED PANELS */

var myPanel = null;
var jQueryTabbedPanels = function(target) {
	
	$("#servicesTabs a").click(function(event) {
		$("#servicesTabs a:focus").css("outline", "none");
		setTabbedPanel($(this).attr("href"));	
		return false;
	});
	
	if (target) {
		setTabbedPanel(target);		
	} else {
		setTabbedPanel("panel1");	
	}
}

var setTabbedPanel = function(target) {
	myPanel = $("#" + target);
	resetTabbedPanels();
}

var resetTabbedPanels = function() {

	// Remove all "Highlite" classes
	var count = 0;
	var num = myPanel.attr("id").substr(5,6);
	$("#servicesTabs ul").find("a").each(function() {
		count++;
		if (String(count) !== num) {
			$(this).removeAttr("class");
		}
		if (String(count) === num) {
			$(this).addClass("highlite");	 
		}
	});
	
	$("#servicesTabs").find("div").each(function() {
		if ($(this).attr("id").indexOf(num) < 0) {
			$(this).removeAttr("class");	
		} else {
			$(this).addClass("highlite");
			$("#panel1 div, ul").css("display", "block");
			//$("#panel1 div, a").css("display", "block");
			//$("#panel1 a").css("text-indent", 20);
		}
	});
}

/*-------------------------------------------
	TS MENUS - IE STATE CONTROLS */
	
var tsMenus = function() {
		var sfEls = document.getElementById("nav").getElementsByTagName("LI");
		for (var i=0; i<sfEls.length; i++) {
			sfEls[i].onmouseover=function() {
				this.className += " sfhover";
			}
			sfEls[i].onmouseout=function() {
				this.className = this.className.replace(new RegExp(" sfhover\\b"), "");
			}
		}	
}



/* ------------------------------------------
	jQUERY VIDEO MODAL */

var setVideoModal = function(_vidPath, _vidName) {
	var modalVideoMarkup = "<div id=\"videoHolder\"></div>";
	
	$.modal(modalVideoMarkup, { position:["50%", "50%"], opacity: [70],
		onOpen:function(dialog) {
			$("#closeWrapper").hide();
			dialog.overlay.fadeIn("slow", function() {
				dialog.data.hide();
				dialog.container.fadeIn("slow",function() {
					dialog.data.fadeIn("slow", function() {
						$("#closeWrapper").fadeIn("slow");	
						swfobject.embedSWF("/lib/swf/videoplayer/videoViewer4x3.swf", "videoHolder", "365", "330", "9.0.0", "", flashvars, params, attributes);
					});										
				});
			});
		},
		onClose:function(dialog) {
			$("#closeWrapper").fadeOut("slow");
			dialog.container.fadeOut("slow", function() {
				dialog.overlay.fadeOut("slow", function() {
					$.modal.close();
				});
			});
		}
	});
	$("#simplemodal-container").addClass("videoPlayer4x3");
	
	var flashvars = {
		clip: _vidPath,
		clipName: _vidName
	};
	var params = {
		wmode: "transparent"
	};
	var attributes = {
		// Do Something
	};
}


/* ------------------------------------------
	jQUERY PHOTO MODAL */

var setPhotoModal = function(_picPath, _picName) {
	var modalPhotoMarkup = "<div id=\"photoHolder\"></div>";
	
	$.modal(modalPhotoMarkup, { position:["50%", "50%"], opacity: [70],
		onOpen:function(dialog) {
			$("#closeWrapper").hide();
			dialog.container.hide();
			dialog.overlay.fadeIn("slow", function() {
				swfobject.embedSWF("/lib/swf/photoViewer/photoViewer.swf", "photoHolder", "492", "522", "9.0.0", "", flashvars, params, attributes);
				dialog.data.fadeIn("slow");
				dialog.container.fadeIn("slow",function() {
						$("#closeWrapper").fadeIn("slow");									
				});
			});
		},
		onClose:function(dialog) {
			$("#closeWrapper").fadeOut("slow");
			dialog.container.fadeOut("slow", function() {
				dialog.overlay.fadeOut("slow", function() {
					$.modal.close();
				});
			});
		}
	});
	$("#simplemodal-container").addClass("photoViewer");
	var flashvars = {
		photoPath: _picPath,
		photoName: _picName
	};
	var params = {
		wmode: "transparent"
	};
	var attributes = {
		// Do Something
	};
}


/*:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: || START 1: URL PARSING  ||:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/

function getFullURL() {
	var locURL = window.location.href;
	return locURL;	
}

function getURLParts() {
	var urlParts = getFullURL();
	var urlSplit = urlParts.split("//");
	var urlFinal = urlSplit[1];
	return urlFinal;
}

function getURLDirectory() {
	var urlParts = getURLParts();
	var urlSplit = urlParts.split("/");
	var urlFinal = urlSplit[(urlSplit.length - 2)];
	return urlFinal;
}

function getURLPage() {
	var urlParts = getURLParts();
	var urlSplit = urlParts.split("/");
	var urlFinal = urlSplit[(urlSplit.length - 1)];
	return urlFinal;
}

function getURLQueryString() {
	var fullURL = getFullURL();
	var qString = fullURL.split("?");
	return qString;
}

function getPageURL(url) {
	var fn = url.match(/\/([a-z0-9_-]+\.\w+)/i);
    return (fn == null) ? "" : fn[1];
}

/*:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: || END 1: URL PARSING  ||:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/
