var popupwin = null;
var first = true;
var previous_url;
var screenHeight = Math.round(screen.availHeight * 0.90)	
function windowOpen(url,openHeight) {		
	if (openHeight > screenHeight) {
		openHeight = screenHeight;
	}
	var winString = "height=" + openHeight + ",width=500,scrollbars=1,status=0,top=20,left=100";
	if (first) {
		popupwin = window.open( url, "breville", winString);
		popupwin.focus();
		first = false;
	} else {
		if ( popupwin != null && !popupwin.closed && previous_url == url ) { popupwin.focus(); }
		else {
			if (popupwin.closed) {
				popupwin = window.open( url, "enquiry", winString);
				popupwin.focus();
			} else {
				popupwin.location = url;
				popupwin.focus();
			}
		}	
	}
	previous_url = url ;
}

$(document).ready(function(){
	// "bug" fix/hack with side by side divs where one div is "longer" than the other
	if ($("#images").height() > $("#content").height()) {
		var minHeight = $("#images").height();
		$("#content").css( { "minHeight": minHeight + "px" } )
		if ($.browser.msie && $.browser.version.substr(0,1)<7) {
			$("#content").css( { "height": minHeight + "px" } ) // IE6 only
		};
	};
	if ($("#images").height() < $("#content").height()) {
		var minHeight = $("#content").height();
		$("#images").css( { "minHeight": minHeight + "px" } )
		if ($.browser.msie && $.browser.version.substr(0,1)<7) {
			$("#images").css( { "height": minHeight + "px" } ) // IE6 only
		};
	};

	
	// if link class = popup then open link in a popup window. Rather than have JS function call inside link onclick
	$('a.popup').click(function() {
		windowOpen($(this).attr("href"),550);
		return false;
	});

	$('h1').flash(
		{ src: 'includes/theSans_semiBold.swf', flashvars: { css: ['* { color: ' + h1_color + '; }'].join(' ')}},
		{ update: false },
		function(htmlOptions) {
			htmlOptions.flashvars.txt = this.innerHTML;
			this.innerHTML = '<span>'+this.innerHTML+'</span>';
			var $alt = $(this.firstChild);
			//htmlOptions.align = "absbottom";
			htmlOptions.height = $alt.height();
			htmlOptions.width = $alt.width();
			htmlOptions.wmode = "transparent";
			$alt.addClass('alt');
			$(this)
				.addClass('flash-replaced')
				.prepend($.fn.flash.transform(htmlOptions));
		}
	);
	
});
