//<script>
var bxx;
$(document).ready(function(){
	//$("#featuredSlides").anythingSlider({height:360, theme: 'minimalist-round', themeDirectory: 'plugin/anythingslider/css/theme-minimalist-round.css', resizeContents: true, delay: 8000});
	try{bxx=$('#featuredSlides').bxSlider({
            auto: true,
            autoControls: false,
            autoHover: true,
            pager: true,
            controls: false,
			speed: 1000,
			pause: 7000
        });
	}catch(e){}
	
	$("#fbscript").attr("src","http://connect.facebook.net/en_US/all.js##appId=117908581596166&amp;xfbml=1");
	window.fbAsyncInit = function() {
		FB.init({appId: '117908581596166', status: true, cookie: true,
				 xfbml: true});
	  };
	moreInfo();
	$.piroBox_ext({
        piro_speed : 900,
        bg_alpha : 0.7,
        piro_scroll : true, //pirobox always positioned at the center of the page
		piro_nav_pos: 'bottom'
    });
	$("div.banners li").hover(
		function(){$(this).find("img").animate({width:"180px",height:"121px",opacity:"1.0", boxShadow:"0 0 0 transparent, 3px 3px 12px rgba(0,0,0,0.8);"},500,function(){});},
		function(){$(this).find("img").animate({width:"150px",height:"101px",opacity:"0.5"},500,function(){});}
	);
	$("input#btnSubmit").button();
	$(".jquerybutton").button();
	$("a.addbutton").button({icons:{primary:"ui-icon-plusthick"}});
	$(".officeinfo").hide();
	$(".officeinfo#welcome").show();
	$(".officenav[data-target]").click(function()
		{
			$(".officeinfo").hide('slow');
			$("#"+$(this).attr("data-target")).show('slow');
			event.preventDefault();
		}
	);
	try{CKEDITOR.replace('txtBody');}catch(e){}
	
	
	$(window).bind('resize', function () { 
		bxx.reloadShow();
	});
});


google.load('search', '1', {language : 'en'});
google.setOnLoadCallback(function() {
    var customSearchControl = new google.search.CustomSearchControl('007053429706030166791:wb-a4jcmqfg');
    customSearchControl.setResultSetSize(5);
    /*    customSearchControl.draw('cse');*/
    
    var options = new google.search.DrawOptions();
    options.setSearchFormRoot(document.getElementById("cse"));
    customSearchControl.setNoResultsString("No results found.");
    customSearchControl.setLinkTarget(google.search.Search.LINK_TARGET_SELF);
    
    customSearchControl.draw(document.getElementById("searchResults"), options);
/* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
    var disqus_shortname = 'quezonprovince'; // required: replace example with your forum shortname

    /* * * DON'T EDIT BELOW THIS LINE * * */
    (function () {
        var s = document.createElement('script'); s.async = true;
        s.type = 'text/javascript';
        s.src = 'http://' + disqus_shortname + '.disqus.com/count.js';
        (document.getElementsByTagName('HEAD')[0] || document.getElementsByTagName('BODY')[0]).appendChild(s);
    }());
}, true);

function fetchNews(el){
	var url = "https://ajax.googleapis.com/ajax/services/search/news?v=1.0&callback=?&q=quezon%20-%22quezon%20city%22";
	$.getJSON(url,function(data){
		$.each(data.responseData.results, function(i,item){
			var d = $("<div>").attr("class","newsItem").appendTo(el);
			$("<a>").attr("href",item.unescapedUrl).html(item.titleNoFormatting).appendTo($("<h2>").appendTo(d));
			$("<span>").attr("class","iso8601Date").attr("title",item.publishedDate).html(new Date(item.publishedDate).toString("ddd, MMMM d, yyyy")).appendTo($("<div>").attr("class","subheading").html(item.publisher + " - ").appendTo(d));
			if(typeof item.image != "undefined")
			{
				$("<div>").attr("class","imgTb").append($("<a>").attr("href",item.image.originalContextUrl).append($("<img>").attr("src",item.image.tbUrl).attr("alt",item.titleNoFormatting))).append($("<div>").html(item.image.publisher)).appendTo(d);
				d = $("<div>").attr("class","content").appendTo(d);
			}
			$("<a>").attr("href",item.signedRedirectUrl).html("Read More").appendTo($("<p>").html(item.content + " ").appendTo(d));
			if(typeof item.relatedStories != "undefined")
			{
				$.each(item.relatedStories, function(j,rel){
					relDiv = $("<div>").attr("class","rel").appendTo(d);
					$("<a>").attr("href",rel.unescapedUrl).attr("class","title").html(rel.titleNoFormatting).appendTo(relDiv);
					$("<span>").html(" - " + rel.publisher).appendTo(relDiv);
				});
			}
		});
	});
}

function fetchWeather(el){
	
	try{
		$.getJSON("/js/weather.js",function(data){
			iconpath="http://icons.wxug.com/i/c/k/";
			el.append(
				$("<img>").attr("src",data.current_observation.icon_url).attr("alt",data.current_observation.weather).attr("title",data.current_observation.weather));
			try{el.append($("<span id=\"temp_c\">").html(data.current_observation.temp_c + "&deg;C"));}catch(e){}
			try{$(".weather .moreinfo .forecast").append($("<p>").html("<strong>Relative Humidity:</strong> " + data.current_observation.relative_humidity));}catch(e){}
			try{$(".weather .moreinfo .forecast").append($("<p>").html("<strong>Wind :</strong>" + data.current_observation.wind_string));}catch(e){}
			$.each(data.forecast.txt_forecast.forecastday,
				function(key, val){
					try{
					var ff = $("<div class=\"futureForecast\">");
					$(".weather .moreinfo .forecast").append(ff);
					ff.append($("<header>").html(val.title));
					ff.append($("<div style='float:left;'>").append($("<img>").attr("title",val.icon).attr("alt",val.icon).attr("src",iconpath+(val.title.match(/Night/)?"nt_":"")+val.icon+".gif")));
					ff.append($("<div>").html(val.fcttext_metric));
					}catch(e){}
				}
			);
		});
	}catch(e){}
}

function moreInfo(){
	$(".moreinfo").before($("<div class=\"moreinfobutton\">").html("<span>&#x25BC; More Info</span>"));
	$(".moreinfo").hide();
	//$(".moreinfobutton").click(function(){
		$(".moreinfobutton").toggle(
			function(){
				$(this).find("span").html("&#x25B2; Less Info");
				$(this).next(".moreinfo").show("slow");
			},
			function(){
				$(this).find("span").html("&#x25BC; More Info");
				$(this).next(".moreinfo").hide("slow");
			}
		);
	//});
}

//Snow 3d

	var SCREEN_WIDTH = window.innerWidth;
	var SCREEN_HEIGHT = window.innerHeight;
	var container;
	var particle;
	var camera;
	var scene;
	var renderer;
	var mouseX = 0;
	var mouseY = 0;
	var windowHalfX = window.innerWidth / 2;
	var windowHalfY = window.innerHeight / 2;
	var particles = []; 
	var particleImage = new Image();
	particleImage.src = '/images/ParticleSmoke.png'; 
	var snowState = true;
	var intId;


function snow3dInit() {

	container = $("#snow").get(0);
	//document.body.appendChild(container);

	camera = new THREE.Camera( 75, SCREEN_WIDTH / SCREEN_HEIGHT, 1, 10000 );
	camera.position.z = 1000;

	scene = new THREE.Scene();

	renderer = new THREE.CanvasRenderer();
	renderer.setSize(SCREEN_WIDTH, SCREEN_HEIGHT);

	for (var i = 0; i < 500; i++) {

		particle = new Particle3D( new THREE.ParticleBitmapMaterial( particleImage));
		particle.position.x = Math.random() * 2000 - 1000;
		particle.position.y = Math.random() * 2000 - 1000;
		particle.position.z = Math.random() * 2000 - 1000;
		particle.scale.x = particle.scale.y =  1;
		scene.addObject( particle );

		particles.push(particle); 
	}

	container.appendChild( renderer.domElement );


	document.addEventListener( 'mousemove', onDocumentMouseMove, false );
	document.addEventListener( 'touchstart', onDocumentTouchStart, false );
	document.addEventListener( 'touchmove', onDocumentTouchMove, false );
}

//

function onDocumentMouseMove( event ) {

	mouseX = event.clientX - windowHalfX;
	mouseY = event.clientY - windowHalfY;
}

function onDocumentTouchStart( event ) {

	if ( event.touches.length == 1 ) {

		event.preventDefault();

		mouseX = event.touches[ 0 ].pageX - windowHalfX;
		mouseY = event.touches[ 0 ].pageY - windowHalfY;
	}
}

function onDocumentTouchMove( event ) {

	if ( event.touches.length == 1 ) {

		event.preventDefault();

		mouseX = event.touches[ 0 ].pageX - windowHalfX;
		mouseY = event.touches[ 0 ].pageY - windowHalfY;
	}
}

//

function loop() {
	if(!snowState) return;

	for(var i = 0; i<particles.length; i++)
	{

		var particle = particles[i]; 
		particle.update(); 

		with(particle.position)
		{
			if(y<-1000) y+=2000; 
			if(x>1000) x-=2000; 
			else if(x<-1000) x+=2000; 
			if(z>1000) z-=2000; 
			else if(z<-1000) z+=2000; 
		}				
	}

	camera.position.x += ( mouseX - camera.position.x ) * 0.05;
	camera.position.y += ( - mouseY - camera.position.y ) * 0.05;


	renderer.render( scene, camera );


}


//End Snow 3d

// All credit goes to Rick Olson.
(function($) {
  $.fn.relatizeDate = function() {
	return $(this).each(function() {
	  $(this).text( $.relatizeDate(this) )
	})
  }

  $.relatizeDate = function(element) {
	return $.relatizeDate.timeAgoInWords( new Date($(element).attr("datetime")) )
  }

  // shortcut
  $r = $.relatizeDate

  $.extend($.relatizeDate, {
	shortDays: [ 'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat' ],
	days: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
	shortMonths: [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ],
	months: [ 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December' ],

	/**
	 * Given a formatted string, replace the necessary items and return.
	 * Example: Time.now().strftime("%B %d, %Y") => February 11, 2008
	 * @param {String} format The formatted string used to format the results
	 */
	strftime: function(date, format) {
	  var day = date.getDay(), month = date.getMonth();
	  var hours = date.getHours(), minutes = date.getMinutes();

	  var pad = function(num) { 
		var string = num.toString(10);
		return new Array((2 - string.length) + 1).join('0') + string
	  };

	  return format.replace(/\%([aAbBcdHImMpSwyY])/g, function(part) {
		switch(part[1]) {
		  case 'a': return $r.shortDays[day]; break;
		  case 'A': return $r.days[day]; break;
		  case 'b': return $r.shortMonths[month]; break;
		  case 'B': return $r.months[month]; break;
		  case 'c': return date.toString(); break;
		  case 'd': return pad(date.getDate()); break;
		  case 'H': return pad(hours); break;
		  case 'I': return pad((hours + 12) % 12); break;
		  case 'm': return pad(month + 1); break;
		  case 'M': return pad(minutes); break;
		  case 'p': return hours > 12 ? 'PM' : 'AM'; break;
		  case 'S': return pad(date.getSeconds()); break;
		  case 'w': return day; break;
		  case 'y': return pad(date.getFullYear() % 100); break;
		  case 'Y': return date.getFullYear().toString(); break;
		}
	  })
	},
  
	timeAgoInWords: function(targetDate, includeTime) {
	  return $r.distanceOfTimeInWords(targetDate, new Date(), includeTime);
	},
  
	/**
	 * Return the distance of time in words between two Date's
	 * Example: '5 days ago', 'about an hour ago'
	 * @param {Date} fromTime The start date to use in the calculation
	 * @param {Date} toTime The end date to use in the calculation
	 * @param {Boolean} Include the time in the output
	 */
	distanceOfTimeInWords: function(fromTime, toTime, includeTime) {
	  var delta = parseInt((toTime.getTime() - fromTime.getTime()) / 1000);
	  if (delta < 60) {
		  return 'less than a minute ago';
	  } else if (delta < 120) {
		  return 'about a minute ago';
	  } else if (delta < (45*60)) {
		  return (parseInt(delta / 60)).toString() + ' minutes ago';
	  } else if (delta < (120*60)) {
		  return 'about an hour ago';
	  } else if (delta < (24*60*60)) {
		  return 'about ' + (parseInt(delta / 3600)).toString() + ' hours ago';
	  } else if (delta < (48*60*60)) {
		  return '1 day ago';
	  } else {
		var days = (parseInt(delta / 86400)).toString();
		if (days > 5) {
		  var fmt  = '%B %d, %Y'
		  if (includeTime) fmt += ' %I:%M %p'
		  return $r.strftime(fromTime, fmt);
		} else {
		  return days + " days ago"
		}
	  }
	}
  })
})(jQuery);

jQuery.cookie=function(d,e,b){if(arguments.length>1&&String(e)!=="[object Object]"){b=jQuery.extend({},b);if(e===null||e===undefined){b.expires=-1}if(typeof b.expires==="number"){var g=b.expires,c=b.expires=new Date();c.setDate(c.getDate()+g)}e=String(e);return(document.cookie=[encodeURIComponent(d),"=",b.raw?e:cookie_encode(e),b.expires?"; expires="+b.expires.toUTCString():"",b.path?"; path="+b.path:"",b.domain?"; domain="+b.domain:"",b.secure?"; secure":""].join(""))}b=e||{};var a,f=b.raw?function(h){return h}:decodeURIComponent;return(a=new RegExp("(?:^|; )"+encodeURIComponent(d)+"=([^;]*)").exec(document.cookie))?f(a[1]):null};function cookie_encode(b){var a=encodeURIComponent(b);var c=a.replace(/(%7B|%7D|%3A|%22|%23|%5B|%5D)/g,function(d){return decodeURIComponent(d)});return c};

