$(function () { //Run when the page loads
	//printServerDate();
	printLocalDate();
	loadScripts();
});


function loadScripts() {
	// Load script files and jQuery plugins separate from the HTML. 
	// http://plugins.jquery.com/project/xLazyLoader
	$.xLazyLoader({
		js: [
			'http://www.google.com/uds/solutions/dynamicfeed/gfdynamicfeedcontrol.js',
			'/resources/dns/includes/jquery.cycle.min.js'
		],
		/*
		css: [],
		img: [''],
		name: '',
		*/
		success: function(){
			loadFeedControl();
			//loadFlickrFeed();
			rotateImages();
		},
		error: function(){

		},
		each: function(url){

		}
	
	});
}

// http://www.roseindia.net/ajax/jquery/jqueryservertime.shtml
function printServerDate() {
	$.ajax({
		url : "http://www.crosscomm.net/resources/dcvb/includes/time.php",
		success : function (data) {
			$("#today").html(data);
		}
	});
	setTimeout("printDate()", 1000);
//*/
}

function printLocalDate() {
	var m_names = new Array("January", "February", "March",
	"April", "May", "June", "July", "August", "September",
	"October", "November", "December");
	var d = new Date();
	var curr_date = d.getDate();
	var curr_month = d.getMonth();
	var curr_year = d.getFullYear();
	var myDate = m_names[curr_month] + ' ' + curr_date + ', ' + curr_year;
	$("#today").html(myDate);
}

// Developer Guide: http://www.google.com/uds/solutions/dynamicfeed/reference.html
function loadFeedControl() {
	var optionsLarge = {
		   numResults : 5,
		   scrollOnFadeOut : false,
		   displayTime : 7000//,
		   //fadeOutTime : 500,
		   //linkTarget : google.feeds.LINK_TARGET_BLANK,
		   //pauseOnHover : true,
		   //horizontal : false,
		   //stacked : true,
		   //title : 'Custom Title',
		   //transitionCallback : myTransitionHandler,
		   //feedLoadCallback : myFeedLoadHandler,
		   //feedTransitionCallback : myFeedTransitionHandler,
	}
	var optionsSmall = {
		   numResults : 3,
		   displayTime : 90000
	}
	var optionsXSmall = {
		   numResults : 1,
		   displayTime : 90000
	}
	var feedMain  = "http://durhamnewsservicemainfeed.blogspot.com/feeds/posts/default";
	var fgMain = new GFdynamicFeedControl(feedMain, "feed-main", optionsLarge);
	var feedGreats  = "http://dnsgreats.blogspot.com/feeds/posts/default";
	var fgGreats = new GFdynamicFeedControl(feedGreats, "feed-greats", optionsSmall);
	var feedKnowbulls  = "http://knowbulls.blogspot.com/feeds/posts/default";
	var fgKnowbulls = new GFdynamicFeedControl(feedKnowbulls, "feed-knowbulls", optionsSmall);
	//var feedSaying = "http://dnswhattheyaresaying.blogspot.com/feeds/posts/default";
	//var fgSaying = new GFdynamicFeedControl(feedSaying, "feed-saying", optionsSmall);
	var feedFeedback  = "http://dnsfeedback.blogspot.com/feeds/posts/default";
	var fgFeedback = new GFdynamicFeedControl(feedFeedback, "feed-feedback", optionsSmall);
	var feedStaff  = "http://greatplacegreatpeople.blogspot.com/feeds/posts/default";
	var fgStaff = new GFdynamicFeedControl(feedStaff, "feed-staff", optionsSmall);
	//var feedFactoid  = "http://dnsfactoid.blogspot.com/feeds/posts/default";
	//var fgFactoid = new GFdynamicFeedControl(feedFactoid, "feed-factoid", optionsXSmall);
}

function loadFlickrFeed() {
	$.getJSON("http://api.flickr.com/services/feeds/photoset.gne?set=72157624480810946&nsid=22230194@N03&lang=en-us&format=json&jsoncallback=?", function(data){
		var latestPhoto = data.items[0];
		$("<img/>").attr("src", latestPhoto.media.m).appendTo("#photoOfTheWeek").wrap("<a href='" + latestPhoto.link + "'></a>");
/*
		$.each(data.items, function(i,item){
			$("<img/>").attr("src", item.media.m).appendTo("#photoOfTheWeek").wrap("<a href='" + item.link + "'></a>");
		});
*/
	});
}

function rotateImages() {
	$('#photoOfTheWeek').cycle({
		timeout:	0,
		fit:		1,
		random:		1
	});
}

//Dreamweaver Behaviors
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
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_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

//Preload tab images
//MM_preloadImages('images/tab-wallpapers-or.png');

