$(document).ready(function() {

	fancybox();

 	scrollpage(); 

	weatherinit();

	initialize();

});



  

function scrollpage()

{

   $('#replyBtn').click(function(){

        $('#replyTitle').ScrollTo(800)

        return false;

        });

      $('#replyBtn2').click(function(){

        $('#replyTitle').ScrollTo(800)

        return false;

        });

      $('#reviewBtn').click(function(){

        $('#reviewTitle').ScrollTo(800)

        return false;

        });

      $('#topBtn').click(function(){

        $('#container').ScrollTo(800)

        return false;

        });

}

//////

 function fancybox()

 { 

 $(".iframe").fancybox({

  'overlayShow'    : true,

  'zoomSpeedIn'    : 600,

  'frameWidth' : 850,

  'frameHeight': 670,

//  'callbackOnShow' : function(){$('object').css('display','block')},

  'callbackOnShow' : function(){$('#fancy_outer').css('display','block')},



  'callbackOnClose' : function(){$('object').css('display','none')},

  'zoomSpeedOut'    : 500,

  'easingIn'    : 'easeOutBack',

  'easingOut'    : 'easeInBack',

  'padding':0

  });

 $(".iframe2").fancybox({

  'overlayShow'    : true,

  'zoomSpeedIn'    : 600,

  'frameWidth' : 750,

  'frameHeight': 470,

//  'callbackOnShow' : function(){$('object').css('display','block')},

  'callbackOnShow' : function(){$('#fancy_outer').css('display','block')},



  'callbackOnClose' : function(){$('object').css('display','none')},

  'zoomSpeedOut'    : 500,

  'easingIn'    : 'easeOutBack',

  'easingOut'    : 'easeInBack',

  'padding':0

  });

  $("#videobox").fancybox({

   'overlayShow'    : true,

  'zoomSpeedIn'    : 600,

//  'callbackOnShow' : function(){$('object').css('display','block')},

  'callbackOnShow' : function(){$('#fancy_outer').css('display','block')},

  'callbackOnClose' : function(){$('object').css('display','none')},

  'zoomSpeedOut'    : 500,

  'easingIn'    : 'easeOutBack',

  'easingOut'    : 'easeInBack',

  'frameWidth' : 853,

  'frameHeight': 505,

  'scrolling':'no'

  });



 $(".sliderimg").fancybox({

  'overlayShow'    : true,

  'zoomSpeedIn'    : 600,

  'frameWidth' : 850,

  'frameHeight': 570,

//  'callbackOnShow' : function(){$('object').css('display','block')},

  'callbackOnShow' : function(){$('#fancy_outer').css('display','block')},



  'callbackOnClose' : function(){$('object').css('display','none')},

  'zoomSpeedOut'    : 500,

  'easingIn'    : 'easeOutBack',

  'easingOut'    : 'easeInBack',

  'padding':0

  });

  



  



  }

  

  

function showreply(reviewid)

{

	$('#ownerreplytext_'+reviewid).show();

	$('#ownerreplybtn_'+reviewid).show();

	$('#ownerreplylink_'+reviewid).hide();

}



function submitreply(id,reviewid)

{

	 	  var replytext=$('#ownerreplytext_'+reviewid).val();

		  replytext=replytext.replace(/\n/g,"[br]");

		  if(!replytext) 

		  {

			  alert("Please input your reply!");

			  return;

		   }

		   if (!( $.browser.msie && parseInt($.browser.version)==6 ))

			$('#sr').css('opacity',0.3);

			$.post("/business/func/getreview.php?"+Math.random(), {

			id:id,

			reviewid:reviewid,

			page:'1',

			order:'time',

			replytext:replytext

			},function(data){

					tips('Reply submitted.');

					nav(data);

			});

}



function check_login(who)

{

    if(!temp) 

    {

		alert("Please login to review!");

    	who.blur();

	}

}

  

 

function get(id,pg,changepage) {

/*

$('#sr').hide();

$('#wait').show();

*/

  if(changepage=="review")  ///// send comment!!

  {

	 



		  var comment=$('#review').val();

		  comment=comment.replace(/\n/g,"[br]");

		  if(!comment) 

		  {

			  alert("Please input your review!");

			  return;

		   }

		  var rating=$('#rating').val();

		  if(!temp) 

			{

				alert("Please Login!");

				return;

			}

		if(document.getElementById('rating').value=='')

	  {

		alert('Please select a star rating! ');  

		return false;

	  }

			if (!( $.browser.msie && parseInt($.browser.version)==6 ))

			$('#sr').css('opacity',0.3);

			$('#review').val('');

			$('#reviewTitle').ScrollTo(200); 

			$.post("/biz/func/getreview.php?"+Math.random(), {

			id:id,

			page:'1',

			order:'time',

			comment:comment,

			rating:rating,

			anonymous:$('#anonymous')[0].checked

			},function(data){

					if(data=='UserReviewAlreadyExist')

					{

						alert("Sorry you have already submitted review for this Business");

						$('#sr').css('opacity',1);

					}

					else if(data=='owner')

					{

						alert('Looks like you are the owner of this business. Please click "edit listing" to add a description about your business.');

						$('#sr').css('opacity',1);

					}

					else

					{

						tips('Review submitted.');

						nav(data);

					}

					 });

 }

  else //not review

  {

	  if (!( $.browser.msie && parseInt($.browser.version)==6 ))

	  $('#sr').css('opacity',0.3);

	  var order=$('#sortby').val();

	  var searchtext = $('#searchtext').val();

	  if(!searchtext||searchtext=="Search Reviews") searchtext='';

			$.post("/biz/func/getreview.php?"+Math.random(), {

			id:id,

			page:pg,

			order:order,

			searchtext:searchtext

			},function(data){

				nav(data);

				});

  }

}



function nav(data)

{

	$('#sr').html(data);

	if (!( $.browser.msie && parseInt($.browser.version)==6 ))

	$('#sr').css('opacity',1);

	/*

	$('#sr').show();

	

	$('#wait').hide();

	*/	

	window.scrollBy(0,-7050);

	fancybox();

}







function sele_item(a,orderby){

for(var i=0;i<document.getElementsByTagName("span").length;i++){

if(document.getElementsByTagName("span")[i].id=="itemid"){

document.getElementsByTagName("span")[i].className='Sitem';

document.getElementById("sortby").value=orderby;

}

}

a.className='SitemS';

get(biz_id,1);

}



function showflag(topicid,replyid,zone){

var d=document.flag;

d.topicid.value=topicid;

d.replyid.value=replyid;

d.zone.value=zone;

document.getElementById('flagform').style.display='';

}





function code2img(code){

     return "http://l.yimg.com/us.yimg.com/i/us/we/52/"+code+".gif";  

  }



function weather2html(weather,cat,alt){  //cat =1 now   2 tomorrow ... 

var imgurl = code2img(weather.code);

var text = weather.text;

var _temp = weather.temp;

var temp = "";

var date= weather.date;

  //"date":"21 May 2009",

  //"text":"Mostly Clear",

  //"day":"Thu",

if (_temp==undefined) {

   var high = weather.high;

   var low = weather.low;

   temp = low+" F ~ "+high+" F";

}

else {

   temp = _temp+" F";

}

  switch(cat)

  {

  case '1':

  $('#current_title').text("Current Weather");

       $('#current_img').attr("src",imgurl);

       $('#current_img').attr("title",alt);

       $('#current_stat').text(text);

       $('#current_text').text(temp+"");

       break;

  case '2':

  var day=weather.day;

  $('#tomorrow_title').text(day);

       $('#tomorrow_img').attr("src",imgurl);

       $('#tomorrow_img').attr("title",text);

       $('#tomorrow_stat').text(text);

       $('#tomorrow_text').text(temp+"");

  break;

  case '3':

  var day=weather.day;

  $('#after_title').text(day);

       $('#after_img').attr("src",imgurl);

       $('#after_img').attr("title",text);

       $('#after_stat').text(text);

       $('#after_text').text(temp+"");

  break;

  }

}



function weatherinit()

{

	

// Weather Forecast Init.

var zipcode=biz_zip;

var url ="http://pipes.yahoo.com/pipes/pipe.run?_id=2eb187fcae6192aee203f670109a40f7&_render=json&u=f&p="+zipcode+"&_callback=?";



    $.getJSON(url, function(data){

    var _item = data.value.items[0];

    var alt=_item['y:title'];

  var y_id=_item['y:id']['value'];

  if(y_id!=null){    

       weather2html(_item["yweather:condition"],'1',alt);

       weather2html(_item["yweather:forecast"][0],'2','');

       weather2html(_item["yweather:forecast"][1],'3','');

       $('.weather').slideDown('slow');

  }

    })

	

}





function initialize() {

//Google Map init.

if(zoom==0)

{

	if(document.getElementById("map_canvas")) {

  		document.getElementById("map_canvas").innerHTML="<br /><br /><br /><br /><br /><center>No Map</center>";

	}

}

else

{

	if(document.getElementById("map_canvas")) {

		var map = new GMap2(document.getElementById("map_canvas"));

		var center = new GLatLng(mapy, mapx);

		map.setCenter(center, zoom);

		var mxy= new GLatLng(y, x);

		var marker = new GMarker(mxy, {draggable: false});

		map.addOverlay(marker);

		map.addControl(new GSmallMapControl());

		map.addControl(new GMapTypeControl());   // Show view toolbar, satellite..

		//map.setMapType(G_HYBRID_MAP);    // Set default view as hybrid

	}

}}

 

 

 function tips(content)

{

	$('#tips').html(content);

	

		var scrolltop = window.pageYOffset  || document.documentElement.scrollTop  || document.body.scrollTop || 0;

		var _clientheight=0;

  			  _clientheight = Math.min(document.body.clientHeight , document.documentElement.clientHeight);

   		if(_clientheight==0)

    		  _clientheight= Math.max(document.body.clientHeight , document.documentElement.clientHeight);

        var _clientwidth= document.documentElement.clientWidth || document.body.clientWidth;

        var _pageheight =  Math.max(document.body.scrollHeight,document.documentElement.scrollHeight);

   

		var msgtop = (scrolltop+(_clientheight)/2)-250+"px";

		var msgleft = ((_clientwidth-650)/2)+"px";



		$('#tips').css('top', msgtop);

		$('#tips').css('left',  msgleft);

		

			$('#tips').show();

			

	setTimeout("$('#tips').hide()",2200);

}



function vote(review_id,type)

{

	$('.vote'+review_id).text("Posting...");

	$.post("/business/func/vote.php?"+Math.random(), { review_id:review_id, type:type},function(data){chgstate(data.state)},"json");

	function chgstate(state){$('.vote'+review_id).html(state);}

}


