$(document).ready(function() {
	/* let's help out by identifying the first and last element in lists */
	$('li:first-child').addClass('first');
	$('li:last-child').addClass('last');
	/* Local scrolling */
	$(".localLinks li").localScroll();
	$(".topLink").localScroll();
	brokerPresentation('#brokerPresentationLink', "#brokerPresentation", "flash/flipbook.swf", {});
	brokerPresentation('#OApresentationLink', "#OApresentation", "flash/OApresentation.swf", {infoURL:'/residential/product_sheets.htm' });
	brokerPresentation('#OApresentationBannerLink', "#OApresentation", "flash/OApresentation.swf", {infoURL:'/residential/product_sheets.htm' });
	
});

if (typeof(isIE6OrLess) == 'undefined') {
	function isIE6OrLess() {
			 version=0
			if (navigator.appVersion.indexOf("MSIE")!=-1){
					temp=navigator.appVersion.split("MSIE");
					version=parseFloat(temp[1]);
			}
			if (version<=6.0 && version !=0) { //NON IE browser will return 0
				return true;
			}
			return false;
	}	
}

function makeOverlay(strSel, flashFile, flashvars) {
		$o = $(strSel);
		$o.empty();
		theId = $o.attr('id');
		$o.append('<div id="'+theId+'_flash"></div><div class="closeButton"><a href="javascript:;"><span class="hideOS">Close</span></a></div>');
		injectFlash('#'+theId+'_flash', flashFile, flashvars);
		$o.find('.closeButton a').click(function(){
			$(this).closest('.dialog').hide();
			$('#overlay').hide();
			return false;
		});
		$o.show();
		$('#overlay').show();
}

function injectFlash(strSel, flashFile, flashvars) {
		var flashvars = (flashvars == "" || flashvars == undefined || flashvars == null || flashvars == {}) ? {} : flashvars;
		var params = {
			wmode:'transparent',
			allowFullScreen:'true'
		};
		expressInstallPath="flash/expressInstall.swf";
		minVersion="9.0.0";

		elId = $(strSel).attr('id');
		swfobject.embedSWF(flashFile, elId, "950", "555", minVersion, expressInstallPath, flashvars, params);
}

function brokerPresentation(linkID, divID, flashFile, flashvars) {
	if (!$(linkID).is('a')){
		return;
	}
	$(divID).before('<div id="overlay"></div>');
	$('#overlay').fadeTo(0,0.7);
	$(linkID).click(function() {
		makeOverlay(divID, flashFile, flashvars);
		return false;
		
	})
	var theId;
	$("#footer").css("z-index",1);
	$("#overlay").css("z-index",2);
	$(divID).css("z-index",1000);
	
}


