/*
|-------------------------------------------------------
| Add Swf
|-------------------------------------------------------
| @container - player container(DIV)
| @swf - Player URL
| @w   - width of Player
| @h   - height of Player
| @id  - swf Object ID/Name
| @vars- variables send to player
*/
function swf(container, swf, w, h, id, vars)
{
	var str = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"  id="'+id+'"';
	str +=' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="'+w+'" height="'+h+'">';
	str +=' <param name="movie" value="'+swf+'" />';
	str +=' <param name="quality" value="high" />';
	str +=' <param name="allowFullScreen" value="true" />';
	str +=' <param name="wmode" value="transparent" />';
	str +=' <param name="AllowScriptAccess" value="always">';
	str +=' <param name="FlashVars" value="'+vars+'" />';
	str +=' <embed src="'+swf+'"';
	str +=' FlashVars="'+vars+'" wmode="transparent" allowfullscreen="true" quality="high"';
	str +=' AllowScriptAccess="always" name="'+id+'" ';
	str +=' pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash"';
	str +=' type="application/x-shockwave-flash" width="'+w+'" height="'+h+'"></embed></object>';
	//document.write(str);	
	$('#'+container).html(str);
}

function changeFont()
{	
	
		Cufon.replace('h1'); 
		Cufon.replace('h2');
		Cufon.replace('h3');
		Cufon.replace('h4');	
		Cufon.replace('.tab');
		Cufon.replace('.headline');
		Cufon.replace('#phone');
	
	nav();
}

function nav()
{
	$('#nav li').hover(
		function(){$(this).addClass('active')},
		function(){$(this).removeClass('active')}
	);	
}

function initBar(val1, val2)
{
	
	$('#from').html(addCommas(val1)+'K');
	$('#to').html(addCommas(val2)+'K');	
	$('#price1').val(val1);
	$('#price2').val(val2);	
	
	val1 = val1/maxPrice*180;
	if(val2=='unlimited')
	{		
		$('#to').html(val2);	
		val2 = 185;	
	}else{		
		val2 = val2/maxPrice*180;
	}
	$('#d1').css('marginLeft', val1+'px');
	$('#d2').css('marginLeft', val2+'px');	
	$('#bar_active').width(val2-val1);
	$('#bar_active').css('marginLeft', val1+'px');
	
	
	
	
	$("#d1").easydrag();
	$('#d1').ondrop(function(){
		var p = $('#bar').offset();
		var p1 = $('#d1').offset();
		var p2 = $('#d2').offset();
		l = p1.left - p.left;
		l1 = p2.left - p.left-5;
		if(l<0) l=0;
		if(l>l1) l = l1;
		$('#d1').css('left', 'auto');
		$('#d1').css('marginLeft', l+'px');	
		
		cal();	
	});
	
	$("#d2").easydrag();
	$('#d2').ondrop(function(){
		var p = $('#bar').offset();
		var p1 = $('#d1').offset();
		var p2 = $('#d2').offset();
		l = p1.left - p.left+5;
		l1 = p2.left - p.left;
		if(l1<l) l1=l;
		if(l1>185) l1 = 185;
		$('#d2').css('left', 'auto');
		$('#d2').css('marginLeft', l1+'px');	
		
		cal();	
	});
}

function cal()
{
	a = parseInt($('#d1').css('marginLeft').replace("px", ""));
	b = parseInt($('#d2').css('marginLeft').replace("px", ""));
	c = b-a;
	d = parseInt(a/180*maxPrice);
	e = parseInt(b/180*maxPrice);
	if(b>180 && b<185)
	{
		e = maxPrice;	
	}
	if(b==185)
	{
		e = "unlimited";	
	}
	
	$('#bar_active').css('marginLeft', a+'px');
	$('#bar_active').width(c);
	$('#from').html(addCommas(d.toString())+'K');
	$('#to').html(addCommas(e.toString())+'K');	
	$('#price1').val(d.toString());
	$('#price2').val(e.toString());	
	
	if(e=='unlimited')
	{
		$('#to').html(addCommas(e.toString()));	
	}
}


function addCommas(nStr)
{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}


function init_thmb()
{
	$('.thmb a').click(
		function(){
			$('.thmb a').removeClass('active');			
			
			imgurl = $(this).attr('rel');
			$('#pic').html('<img src="'+imgurl+'" />');
			$(this).addClass('active');	
		}
	);
}

function search_real(val)
{
	type1 = $('input:checked').val();
	ptype1 = $('#ptype').val();
	location1 = $('#location').val();
	p1 = $('#price1').val();
	p2 = $('#price2').val();
	
	if(ptype1=='')
	{
		alert('Please select property type!');
		return false;
	}
	if(location1=='')
	{
		alert('Please select location!');
		return false;
	}
	
	url = val+'index.php/realestate/index/'+ptype1+'/'+type1+'/'+location1+'/'+p1+'_'+p2;
	location = url;
}
