/*
 * General config
 * By poppo 
 * E-Mail: pop@silvermover.com
 * 
 */
var rootFolder="/";
//var rootFolder="/condo-pattaya2/";
var $url="http://"+document.domain+rootFolder; // for page with Rewrite URL
//var $url="";
var ar=[];
$(function(){
	
	$.event.add( window, "load", function(){
             // put preloader in here if send param with Array only
             //preloadImages(bannerSlide);
				/*
				$.each(bannerSlide,function(i,v){
					//preloadImages(v);
                                        $('#slideBanner').append('<img src="' +$url+v+'" width="920" height="250"\/>');
                                        //ar[i]={'src':"'"+$url+v+"'" ,'dir':"'up'"};
					});
				*/
					
                                        $('#slideBanner').cycle({
                                            fx:'fade', // fx: shuffle , turnDown ,curtainX ,fade ,zoom  ,slideY
                                            //easing: 'bounceout',
                                            delay:-8000 });
                                        
                                        /*
                                        $('#slideBanner').crossSlide({
                                        speed: 45,
                                        fade: 1
                                      }, [ar]);
                                        */                                   
								
				} );	
	//$("img").lazyload({placeholder : "images/grey.gif"});
	
	//mobilymap
	$('.pattaya_map').mobilymap({
		position: '10 445',
		popupClass: 'bubble',
		markerClass: 'point',
		//popup: false,
		cookies: false,
		caption: false,
		setCenter: true,
		//navigation: false,
		outsideButtons: '.map_buttons a',
		navSpeed: 6000,
		onMarkerClick: function() {
			/*
			var text = $(this).text();
			alert(text);
			*/
		}
	});
	
$('a').click(function(){
		if($(this).attr('href')=="#"){
			return false;
			}
		});


	$('.fulldetail').button({icons: {
                primary: 'ui-icon-search'
            },
            text: true
	});
$(':submit,.gPage').button();
$('#openpricerange').button({icons: {
                primary: 'ui-icon-triangle-1-s'
            },
            text: true});

//$('input[type="text"]').addClass('text');
$('#format').buttonset();

	$('.hrefcondo').button({icons: {
                //primary: 'ui-icon-search'
            },
            text: true
	});


   $('.closeboxcondo').live('click',function(){
	  $(this).parent().slideUp();
	  return false;
   });


	$('a.remove_condo').live('click',function(){
		var val = $(this).attr('title');
		//alert(val);
			$.getJSON($url+"jax.php",{flag:'removemycondo',id:val},function(data){
				$('#boxmycondo').html(data.remove_condo);
				$('#boxmycondo').slideDown('slow');
				
					});
		return false;
		});

	$('.condoimg,.bigimgofcondo,#thumbnails img').error(function(){
		$(this).attr('src',$url+'pictures/no_image.jpg');
	});

$('body').append('<div id="orderBox" class="ui-corner-all" ></div>');


//-----------------compare-----------
	$('#compare').live('click',function(){
		
		$.getJSON("jax.php",{flag:'mycompare'},function(data){
			//alert(data.compare_condo);
		
			$('#orderBox').html(data.compare_condo);
			});
				scrollTo(0,0);
				switchEOS(1);
				$('body').append('<div id="order-overlay"></div>');
				
				var arrPageSizes = ___getPageSize();
				$('#order-overlay').css({
				backgroundColor:'#333',
				opacity:	0.7,
				'position':'absolute',
				'top':'0px',
				'left':'0px',
				'z-index':'200',
				width:arrPageSizes[0],
				height:(($('#orderBox').height()>arrPageSizes[1])?($('#orderBox').height()+50):arrPageSizes[1])
			}).fadeIn();
				$('#orderBox').css({'left':(arrPageSizes[0]-$(this).width())/2.5}).show().animate({'top':'0px'},1200,'backinout');
				
			$(window).resize(function() {
				var arrPageSizes = ___getPageSize();
				$('#order-overlay').css({
					width:		arrPageSizes[0],
					height:		arrPageSizes[1]
				});
			});
			
		
			return false;
	});


	$('.CloseOrderBox').live('click',function(){
		$('#orderBox').animate({'top':$('#orderBox').height()-($('#orderBox').height()*2.2)},500,'linear',function(){
			$(this).hide();
			switchEOS(0);
			});
	
		$('#order-overlay').remove();
		
		return false;
		});
//-----------------end compare-----------

// new compare

	$('body').append("<div style='width:226px;position:absolute;background:#fff;display:none;' id='compareBox' ><div id='dt'><h3>Compare Listings</h3><a href='#' id='closeCompareBox'><img src='"+ $url +"images/close-orderbox-button.gif' alt='' style='width:18px;border:none;'/><\/a></div><div id='dc'>loading...</div><div id='db'></div><\/div>");
/**/	

	
	$('a.acompare').click(function(){
	
		var val = $(this).attr('title');
		var $parent=$(this).parent().parent().parent().parent();
		var $offset=$parent.offset();
		var cpLeft=$offset.left+$parent.width()+15;
		
		if(cpLeft+250>$('body').width())
		{
			cpLeft=$('body').width()-250;
		}
				$('#dc').html('loading...');
				$('#compareBox').css({top:($offset.top)+15,left:cpLeft}).show();
			$.getJSON($url+"jax.php",{flag:'addcompare',id:val},function(data){
				$('#dc').html(data).slideDown();
				});
			return false;
		});
	
	// remove condo in list compare box
	$('a.closecondo').live('click',function(){
		var val = $(this).attr('title');
		$.getJSON($url+"jax.php",{flag:'delcompare',id:val},function(data){
				$('#dc').html(data).slideDown();
				});
			return false;
		});
	$('a.removelistcondo').click(function(){
		var val = $(this).attr('title');
		$.getJSON($url+"jax.php",{flag:'delcompare',id:val},function(data){
				//$('#dc').html(data).slideDown();
				location.reload();
				});
			return false;
		});
	
	
	//end new compare



 /******* tooltip ********/

   $('a.toolTip').qtip({
		content:{
			 title: {
                     text: ''
                  } 
			},
      position: {
         corner: {
            target: 'topRight',
            tooltip: 'bottomLeft'
         }
      },
      style: {
      width: 200,
      padding: 5,
      background: '#d9ecff',
      color: 'black',
      textAlign: 'left',
	  fontSize: '11px',
	  title: { 'font-size': 10 },
      border: {
         width: 4,
         radius: 5,
         color: '#379bff'

         },
         tip: true
      },
	  hide: { effect: { type: 'slide' } },
	  show: { effect: { type: 'slide' } }
   }).hover(function(){
	//var t="Price is in Thai B, other currencies are estimates only and will vary day by day.";
	var t= $(this).attr('rel');
	var ti= "Pattaya Condo Guide";
	$('.qtip-content').html(t);
	$('.qtip-title').html(ti).css({'background':'#fff'});
	}).click(function(){return false;});
   

/*********end tooltip***********/




if($.browser.msie){
	if($.browser.version<7.0)
	 $(window).scroll(function(){
      $("#divboxflag").css({top:$('html').offset().top,right:0});
	 });
    
}

$('input:text,textarea').focus(function(){
		$(this).css({background:'#F0F0F0',border:'#666 1px solid'});
		
	}).blur(function(){
		$(this).css({background:'#fff',border:'#ddd 1px solid'});
	});

// add my condos---------------------------------------------------
   $("#mycondos").click(function() {
	  $.getJSON($url+"jax.php",{flag:'showsavecondo'},function(data){
		
		$('#boxmycondo').html(data.listdata);
		$('#boxmycondo').slideDown('slow');
		
		});
	  return false;
	  });
   
$('.saveunit').click(function(){
	var val = $(this).attr('title');
	$('#boxmycondo').html('').hide();
		$.getJSON($url+"jax.php",{flag:'savecondounit',id:val},function(data){
				if(data.flag==false){
					window.location = $url + "sign-in.html";
				}else{
				//$('#boxmycondo').scrollTo();
				$('#boxmycondo').html(data.html).hide();
				$('#sign').scrollTo(500,function(){
					$('#boxmycondo').slideDown('slow');
					location.reload();
					});
					}
				});
				
			return false;
	});

	$('#closeCompareBox').live('click',function(){
			$('#compareBox').slideUp();
			return false;
		});

	$('#gototop').click(function(){
		$('#wrapper').scrollTo(2000);
		});

/*
$('img').load(function(){
	window.setTimeout( 'loadFaceBook()', 5000);
});
*/
$('.fbRecomment2').html('<fb:like-box href="http://www.facebook.com/pages/Pattaya-Condo-Guide/149979091720343" width="226" show_faces="true" stream="true" header="true"></fb:like-box>'); 
   $('.fbRecomment').html('<fb:activity site="http:\/\/pattayacondoguide.com\/" width="225" height="450" header="true" font="verdana" recommendations="true"><\/fb:activity>');   
  
	$('.mapclick').live('click',function(){
		var aID = $(this).attr('rel');
		$('#'+aID).scrollTo(2000);
		});  
   
   
}); // n doc

function loadFaceBook()
{
$('header').append("<fb:like href='"+(document.location.href)+"' layout='box_count' font='verdana'></fb:like>");
		//$.getScript("http://connect.facebook.net/en_US/all.js#xfbml=1",function(){
			$('.fb_div').html("<iframe src='http://www.facebook.com/plugins/like.php?href=" +((document.location.href))+ "&amp;layout=standard&amp;show_faces=true&amp;width=100%&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=80' scrolling='no' frameborder='0' style='border:none; overflow:hidden; width:100%; height:80px;' allowTransparency='true'></iframe>");	
/*			
$('.fbRecomment2').html('<fb:like-box href="http://www.facebook.com/pages/Pattaya-Condo-Guide/149979091720343" width="226" show_faces="true" stream="true" header="true"></fb:like-box>'); 
   $('.fbRecomment').html('<fb:activity site="http:\/\/pattayacondoguide.com\/" width="225" height="450" header="true" font="verdana" recommendations="true"><\/fb:activity>');
 */
  // }); 
}

function formatText(index, panel) {
	  return index + "";
};
		  
//---------------VVVVV--------------
function ___getPageSize() {
			var xScroll, yScroll;
			if (window.innerHeight && window.scrollMaxY) {	
				xScroll = window.innerWidth + window.scrollMaxX;
				yScroll = window.innerHeight + window.scrollMaxY;
			} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
				xScroll = document.body.scrollWidth;
				yScroll = document.body.scrollHeight;
			} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
				xScroll = document.body.offsetWidth;
				yScroll = document.body.offsetHeight;
			}
			var windowWidth, windowHeight;
			if (self.innerHeight) {	// all except Explorer
				if(document.documentElement.clientWidth){
					windowWidth = document.documentElement.clientWidth; 
				} else {
					windowWidth = self.innerWidth;
				}
				windowHeight = self.innerHeight;
			} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
				windowWidth = document.documentElement.clientWidth;
				windowHeight = document.documentElement.clientHeight;
			} else if (document.body) { // other Explorers
				windowWidth = document.body.clientWidth;
				windowHeight = document.body.clientHeight;
			}	
			// for small pages with total height less then height of the viewport
			if(yScroll < windowHeight){
				pageHeight = windowHeight;
			} else { 
				pageHeight = yScroll;
			}
			// for small pages with total width less then width of the viewport
			if(xScroll < windowWidth){	
				pageWidth = xScroll;		
			} else {
				pageWidth = windowWidth;
			}
			arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
			return arrayPageSize;
		};
		
		function switchEOS(y){
			$('embed, object, select').css({ 'visibility' : ((y==1)?'hidden':'visible')});
		}
		
		function validFileUpload(id){
			$(id).change(function() {
						if ($(this).val()) { 
							var pattern = "jpe?g";
							var string=$(this).val().toLowerCase();
							if (string.match(new RegExp(".(" + pattern + ")$")) == null) {
								$(this).empty().val('');
								alert( 'Please choose .jpg file only'); return;
							} else { 
								//alert('valid'); 
							}
						} 
				});
			
		} //




//-------------^^^^^^^-------------------



function preloadImages(args){
	if(document.images){
		if(!document.imageArray) document.imageArray = new Array();
		//var i,j = document.imageArray.length, args = preloadImages.arguments;
                var i,j = document.imageArray.length;
		for(i=0; i<args.length; i++){
			if (args[i].indexOf("#")!=0){
				document.imageArray[j] = new Image;document.imageArray[j++].src = args[i];
			}
		}
	}
	
} // n fnc
function hideObj(){
	$('embed, object, select').css({ 'visibility' : 'hidden' });
} //

function showObj(){
	$('embed, object, select').css({ 'visibility' : 'visible' });
} //


// plugin Scrolling page
$.fn.extend({scrollTo:function(speed,easing){return this.each(function(){var targetOffset=$(this).offset().top;$('html,body').animate({scrollTop:targetOffset},speed,easing);});}});

