// JavaScript Document

//places random image on the left panel
function placeLeftImage()
{
	var image_count = 7;
	var random_num = Math.round((image_count - 1) * Math.random()) + 1;
	return '<style type="text/css" media="all">\n #main_left_panel { \n background-image:url(images/left/' + random_num + '.jpg); \n } \n </style> \n';
}

//makes all 3 panels snap to same size to a total of 'snap_stickiness' pixels
function matchDivHeight()
{
	//vars
	var snap_stickiness = 50;
	var corner_flag = false;
	
	//divs to use
	var main_content_div = document.getElementById('main_content');
	var main_content_div_resizer = document.getElementById('main_content_2');
	var property_list_div = document.getElementById('featured_content_container_3');
	var property_list_div_resizer = document.getElementById('featured_content_container');
	var left_panel_div = document.getElementById('main_left_panel');
	var left_panel_div_resizer = document.getElementById('main_left_panel_2');
	
	//sets initital heights (declared in css)
	var main_content_div_height_init = 510;
	var left_panel_div_height_init = 510;
	var property_list_div_height_init = 502;
	
	//gets current heights
	var main_content_div_height = main_content_div.offsetHeight;
	var left_panel_div_height = left_panel_div.offsetHeight;
	var property_list_div_height = property_list_div.offsetHeight;
	
	//starts resizing
	if(main_content_div_height > main_content_div_height_init || property_list_div_height > property_list_div_height_init)
	{
		//gets difference of start and new heights
		var main_content_div_height_diff = main_content_div_height - main_content_div_height_init;
		var property_list_div_height_diff = property_list_div_height - property_list_div_height_init;
		
		//resizes main content
		if(property_list_div_height_diff > main_content_div_height_diff && property_list_div_height_diff <= snap_stickiness)
		{
			main_content_div_resizer.style.height = main_content_div_height_init + property_list_div_height_diff;
			left_panel_div_resizer.style.height = left_panel_div_height_init + property_list_div_height_diff;
			corner_flag = true;
		}
		
		//resizes property list
		if(property_list_div_height_diff <= main_content_div_height_diff && main_content_div_height_diff <= snap_stickiness)
		{
			property_list_div_resizer.style.height = (property_list_div_height_init + main_content_div_height_diff) + 'px';
			left_panel_div_resizer.style.height = (left_panel_div_height_init + main_content_div_height_diff) + 'px';
			corner_flag = true;
		}
		
		//hides corner image on bottom of main content if left panel is the same height as the main content
		if(corner_flag || property_list_div_height_diff == main_content_div_height_diff)
		{
			var left_panel_image = document.getElementById('left_panel_image_js');
			left_panel_image.src = 'images/main_bottom_shadow.gif';
			left_panel_image.style.width = '9px';
			left_panel_image.style.height = '6px';
		}
	}
}

//stops sifr flicker
function runSIFRDebug()
{
	if (flashinstalled > 0 && Math.floor(flashversion) >= 7 && document.getElementsByTagName && document.getElementsByTagName('html')[0])
	{
		document.getElementsByTagName('html')[0].className += (document.getElementsByTagName('html')[0].className=='')?'hasFlash':' hasFlash';
	}
}

//sets sifr swaps
function runSIFR()
{
	//global var:
	var helveticaneue = {
		src: 'sifr/helveticaneue.swf'
	};
	
	sIFR.debugMode = true;
	sIFR.delayCSS  = true;
	
	sIFR.activate(helveticaneue);
	
	sIFR.replace(helveticaneue, {
		selector: 'h2.sifr_blu',
		css: [ '.sIFR-root { color:#0054EA; }' ]
	});
	
	
	sIFR.replace(helveticaneue, {
		selector: 'h2.sifr_white_bg',
		css: [ '.sIFR-root { color:#0154EA; }' ]
	});
	
	
	sIFR.replace(helveticaneue, {
		selector: 'h2.sifr_green_bg',
		css: [ '.sIFR-root { background-color:#BBFF00; color:#0154EA; }' ]
	});	
	
	sIFR.replace(helveticaneue, {
		selector: 'h3.sifr_blue_bg',
		css: [ '.sIFR-root { background-color:#0054EA; color:#BBFF00; }' ]
	});	
	
	sIFR.replace(helveticaneue, {
		selector: 'h2.sifr_blue_bg',
		css: [ '.sIFR-root { background-color:#0054EA; color:#BBFF00; }' ]
	});	
	//alert(helveticaneue);
}

//checks if swfir can run
function runSWFIRInit(is_onload)
{
	if (flashinstalled > 0 && flashversion >= 7)
	{
		var ie6_check = detectIE6();
		
		if(!ie6_check && is_onload == "false" || ie6_check && is_onload == "true")
		{
			runSWFIR();
		}
	}
}

//runs swfir
function runSWFIR()
{
	round = new swfir();
	round.specify('src', 'swfir/swfir.swf');
	round.specify('border-color', 'ffffff');
	round.specify('border-radius', '8');
	round.swap(".featured_content_item img");
	round.swap("#featured_content_1st_pos_container img");
}

//write copyright information - used for easily updating year
function footerCopyright()
{
	return 'Copyright &copy;2007';
}

//detects ie6
function detectIE6 ()
{
	var browser_ie6 = false;
	var browser_version = navigator.appVersion;
	var msie_index = browser_version.indexOf("MSIE");
	
	if(msie_index != -1)
	{
		var browser_details = browser_version.substr(msie_index + 5, 8);
		
		if(parseFloat(browser_details) == 6)
		{
			browser_ie6 = true;
		}
	}
	return browser_ie6;
}

//detects flash version - also uses vb in head
function detectFlash()
{
	flashinstalled = 0;
	flashversion = 0;
	MSDetect = "false";
	if (navigator.plugins && navigator.plugins.length)
	{
		x = navigator.plugins["Shockwave Flash"];
		if (x)
		{
			flashinstalled = 2;
			if (x.description)
			{
				y = x.description;
				flashversion = y.charAt(y.indexOf('.')-1);
			}
		}
		else
			flashinstalled = 1;
		if (navigator.plugins["Shockwave Flash 2.0"])
		{
			flashinstalled = 2;
			flashversion = 2;
		}
	}
	else if (navigator.mimeTypes && navigator.mimeTypes.length)
	{
		x = navigator.mimeTypes['application/x-shockwave-flash'];
		if (x && x.enabledPlugin)
			flashinstalled = 2;
		else
			flashinstalled = 1;
	}
	else
		MSDetect = "true";
}
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_jumpMenuGo(selName,targ,restore){ //v3.0
  var selObj = MM_findObj(selName); if (selObj) MM_jumpMenu(targ,selObj,restore);
}


function switchTrader() {
	
    if(document.forms['property_top_left_selling'].trader){
		for (var i=0; i < document.forms['property_top_left_selling'].trader.length; i++){
			var which = document.forms['property_top_left_selling'].trader[i].value;
			
			if (document.forms['property_top_left_selling'].trader[i].checked) {
				document.getElementById(which + 'block').style.display = 'block';
			}else{
				document.getElementById(which + 'block').style.display = 'none';
				
			}
		}
	}
}
