$(document).ready(function() {
/*
	Light Box Script
*/

	var popID = "";
	
	//Trigger light box
	$("a.reBox").click(function(){
	
		$('#fade').remove();
		
		// Get Popup Name from href "rel"
		popID = $(this).attr('rel'); 
		
		// Check for options in the rel tag
		popID = popID.split("|");
		reBoxHeight = "300";
		reBoxWidth = "500";
		reBoxbgColor = "#fff";
		borderColor = "#002C51";
		
			if (popID[1]) {
				popOptions = popID[1];
				if (getlOption("h") != "") {
					reBoxHeight = getlOption("h");
					$("div.reBox").css("height", reBoxHeight + "px");
				}
				if (getlOption("w") != "") {
					reBoxWidth = getlOption("w");
					$("div.reBox").css("width", reBoxWidth + "px");
				}
				if (getlOption("bgColor") != "") {
					reBoxbgColor = getlOption("bgColor");
					$("div.reBox").css("backgroundColor", reBoxbgColor);
				}
				if (getlOption("borderColor") != "") {
					borderColor = getlOption("borderColor");
					$("div.reBox").css("borderColor", borderColor);
				}
				if (getlOption("scrolling") != "") {
					scrolling = getlOption("scrolling");
				}
				if (getlOption("type") != "") { 
					type = getlOption("type");
					if (type == "iframe") {
						
						if (scrolling == "no") {
							var isie6 = " scrolling='no' ";	
							if(typeof document.body.style.maxHeight === "undefined") {
						       isie6 += " horizontalscrolling='no' verticalscrolling='no' ";
							}
						} else {
							var isie6 = "";
							if(typeof document.body.style.maxHeight === "undefined") {
						       isie6 += " scrolling='yes' horizontalscrolling='no' verticalscrolling='yes' ";
							}
						}
						$('body').append("<div class='reBox' id='" + popID[0] + "'></div>");
						$("div#" + popID[0]).css("height", reBoxHeight + "px").css("width", reBoxWidth + "px").css("backgroundColor", reBoxbgColor).css("borderColor", borderColor);
						
						iframePath = $(this).attr('href');
						$('#' + popID).append("<iframe height='" + (reBoxHeight - 15) +"' width='" + (reBoxWidth) + "' frameborder='0'" + isie6 + "src='" + iframePath + "'></iframe>");
					}
				}
			}
			
			$("div.reBox").prepend("<div id='reBoxTitle'><span><a href='#' title='Close' style='float: right; color: #fff; text-decoration: none; padding-right: 12px;'>X</a></span>" + $(this).attr('title') + "</div>");
		


// Start: ENTCR 12107 Reliant.com Rebrand 
			// Open the calendar lightbox
			$('body').append('<div id="fade"></div>'); 
			//$('#fade iframe').css({'filter' : 'alpha(opacity=1)'});
			$('#fade').css({'height' : $(document).height()}).fadeIn(function() {
			
				$("#" + popID).appendTo("#fade").show();
				$("#" + popID).center();
				$(window).bind('scroll resize', function (){
					$("div.reBox").center();		
					$('#fade').css({'height' : $(document).height()})
				});
			
			});
// End: ENTCR 12107 Reliant.com Rebrand 


		// Open the reBox
/*
		$("#" + popID).show();
		$("#" + popID).center();
		$('body').append('<div id="fade"></div>'); 
		$('#fade').css({'filter' : 'alpha(opacity=80)'}).css({'height' : $(document).height()}).fadeIn();
*/		
		// Recenter reBox on scroll or window resize
/*
		$(window).bind('scroll resize', function (){
			$("div.reBox").center();		
			$('#fade').css({'height' : $(document).height()})
		});
*/


		
		return false;
	});
	
	// Cloase the reBox when background is clicked
	$("#fade").live('click', function() { cleanUp(); });
	$("#reBoxTitle a").live('click', function() { cleanUp(); return false; });
	$("a.closereBox").live('click', function() { cleanUp(); return false; });
	
	
// Start: ENTCR 12107 Reliant.com Rebrand 				
	// Close the opened reBox
	function cleanUp() {
		if (type == "iframe") {
			$('#' + popID).remove();
		} 
		$("#reBoxTitle").remove();
		$('#' + popID).hide();
		$("#" + popID).attr("style" , "").appendTo("body");
		$('#fade').remove();
	}
// End: ENTCR 12107 Reliant.com Rebrand 		
	
	//Process options from rel tag of clicked link
	function getlOption(variable) {
		var notFound = "";
		var vars = popOptions.split("&");
	
			for (var i=0;i<vars.length;i++) {
				var pair = vars[i].split("=");
				if (pair[0] == variable) { return pair[1]; }
			} 
			
		return notFound;
	} 
	
	// Centering function
	jQuery.fn.center = function () {
		this.css("top", ( $(window).height() - this.height() ) / 2+$(window).scrollTop() + "px");
		this.css("left", ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + "px");
		return this;
	}

});

