﻿var urlToLoadOnPopupClose = null;

$(function() {
	if($.browser.msie) {
		var selects = $("select.styled");
		selects.focus(function(){
			if($(this).css("width") != "auto") {
				$(this).data("origWidth", $(this).css("width"));
				$(this).css("minWidth", $(this).css("width"));
				$(this).css("position", "absolute");
				$(this).parent().css("paddingBottom", "18px");

				$(this).css("width", "auto");
				if ($(this).width() < parseInt($(this).data("origWidth"))) {
					$(this).css("width", $(this).data("origWidth"));
				}
				return false;
			}
		});
		selects.blur(function(){
			$(this).css("width", $(this).data("origWidth"));
			$(this).css("position", "static");
			$(this).parent().css("paddingBottom", "0px");
		});
		selects.change(function(){
			$(this).css("width", $(this).data("origWidth"));
			$(this).css("position", "static");
			$(this).parent().css("paddingBottom", "0px");
		});
	}
});

function openImagePopup(url, e) {
	var popupOverlay = document.createElement('div');
	popupOverlay.id = 'popupOverlay';
	$(popupOverlay).css('height', $(window).height() > $(document).height() ? $(window).height() : $(document).height());
	$(popupOverlay).opacity(0.7);
	$(popupOverlay).click(hideImagePopup);

	if($.browser.msie) {
		document.body.appendChild(popupOverlay);
	} else {
		$('body').append(popupOverlay);
	}

	var image = document.createElement('img');
	image.className = 'magnified';
	image.id = 'popupMagnified';
	image.src = url;
	image.width = 400;
	image.height = 300;
	$(image).css('top', $(document).scrollTop() + 100);
	$(image).click(hideImagePopup);
	//$(image).hide();

	if($.browser.msie) {
		document.body.appendChild(image);
	} else {
		$('body').append(image);
	}
	
	//$(image).show('slow');
}

function openPopup(url, height, newUrl, width) {
	var popupOverlay = document.createElement('div');
	popupOverlay.id = 'popupOverlay';
	$(popupOverlay).css('height', $(window).height() > $(document).height() ? $(window).height() : $(document).height());
	$(popupOverlay).opacity(0.7);
	$(popupOverlay).click(hidePopup);
	$('body').append(popupOverlay);

	// IFRAME FOR CONTENT
	var popupBoxContent = document.createElement('iframe');
	popupBoxContent.id = 'popupBoxContent';
	popupBoxContent.src = url;
	popupBoxContent.setAttribute('frameBorder','no');
	popupBoxContent.setAttribute('border','0');
	$(popupBoxContent).corners(11);
	$(popupBoxContent).css('height', height);

	// CLOSE BUTTON
	var popupBoxClose = document.createElement('div');
	popupBoxClose.id = 'popupBoxClose';
	popupBoxClose.innerHTML = '<!-- SPACER -->';
	$(popupBoxClose).click(hidePopup);


	// CONTAINER DIV
	var popupBox = document.createElement('div');
	popupBox.id = 'popupBox';
	$(popupBox).css('top', $(document).scrollTop() + 45);
	$(popupBox).append(popupBoxContent);
	$(popupBox).append(popupBoxClose);
	if($.browser.msie) {
		document.body.appendChild(popupBox);
	} else {
		$('body').append(popupBox);
	}
	$(popupBox).show();

	if (typeof(newUrl) == 'string') {
		urlToLoadOnPopupClose = newUrl;
	} else {
		urlToLoadOnPopupClose = null;
	}
	return false;
}

function hideImagePopup() {
	$("#popupOverlay").remove();
	$("#popupMagnified").remove();
}

function hidePopup(url) {
	if (typeof(url) == 'string') {
		location.href = url;
		return;
	}
	
	if (urlToLoadOnPopupClose != null && typeof(urlToLoadOnPopupClose) == 'string') {
		location.href = urlToLoadOnPopupClose;
		return;
	}
	
	$("#popupOverlay").remove();
	$("#popupBox").remove();
}

function toggleAlternativeMenu() {
	var block = $("#alternative").get(0);
	var button = $("#ctl00_alternativeMenuButton").get(0);

	block.style.left = (button.offsetLeft - 179) + 'px';
	$("#alternative").toggle();

	return false;
}