$(window).bind('load', function(){
   var preload = [
     '../img/scrollleft.gif',
     '../img/scrollright.gif'
   ];           
   $(document.createElement('img')).bind('load', function(){
    if(preload[0]) this.src = preload.shift();
   }).trigger('load');
});


$(document).ready(function(){
						   
		//get latest blog posts
		get_rss_feed();
		
		var position = $("#stickyScroller").position();				   
	
		$("a.scrollLeft", this).click(function(){
			
			position = $("#stickyScroller").position();
			if(position.left < 0){
				$("#stickyScroller").animate({"left": "+=140px"}, "medium");
			}
			v = setTimeout("setStates()", 600);
		});
		
		$("a.scrollRight", this).click(function(){
			position = $("#stickyScroller").position();
			if(position.left > -849 || position.left == 0){
				$("#stickyScroller").animate({"left": "-=140px"}, "medium");
				
			}
			v = setTimeout("setStates()", 600);
			
		});
		
		if(position.left == 0){
			$("#scrollLeft").removeClass("scrollLeft");
			$("#scrollLeft").addClass("scrollLeftOff");
		}
		
		if ($('#fiWOM')) {
			$("div.test", this).hide();	
			testimonials=new Array();
			testimonials = $("div.test");
			selectTest();
		}

});

function get_rss_feed() {
			//clear the content in the div for the next feed.
			$("#feedContent").empty();
			
			//use the JQuery get to grab the URL from the selected item, put the results in to an argument for parsing in the inline function called when the feed retrieval is complete
			$.get('proxy.php?url=http://www.flowinteractive.com.au/blog/?feed=rss2', function(d) {
				
				//find each 'item' in the file and parse it
				$(d).find('item').each(function(i) {
					
					//name the current found item this for this particular loop run
					var $item = $(this);
					// grab the post title
					var title = $item.find('title').text();
					// grab the post's URL
					var link = $item.find('link').text();
					// next, the description
					var description = $item.find('description').text();
					//don't forget the pubdate
					var pubDate = $item.find('pubDate').text();
					
					// now create a var 'html' to store the markup we're using to output the feed to the browser window
					var html = "<p><a href=\"" + link + "\" target=\"_blank\">" + title + "<\/a><\/p>";
					
					//put that feed content on the screen!
					$('#feedContent').append($(html));  
					
					return (i != 2);
				});
			});
			
		};
		
function selectTest(jp) {
	var j = Math.floor( Math.random() * ( 1 + 1 ) );
	if (j == jp) {
		j = j+1;
	}
	for (i = 0; i < testimonials.length; i++) {
		$(testimonials[i]).hide();
	}
	if (testimonials[j] == "" || j == null) {
		$(testimonials[1]).animate({
	   opacity: 'show'
	 }, 1000);
	}
	else {
		$(testimonials[j]).animate({
	   opacity: 'show'
	 }, 1000);
	}
	var delay = setTimeout("selectTest(" + j + ")",10000)
}


function setStates() {
	var position = $("#stickyScroller").position();
	if(position.left < 0){
		$("#scrollLeft").removeClass("scrollLeftOff");
		$("#scrollLeft").addClass("scrollLeft");
	} else {
		$("#scrollLeft").removeClass("scrollLeft");
		$("#scrollLeft").addClass("scrollLeftOff");
	}
	if(position.left <= -849){
		$("#scrollRight").removeClass("scrollRight");
		$("#scrollRight").addClass("scrollRightOff");
	} else {
		$("#scrollRight").removeClass("scrollRightOff");
		$("#scrollRight").addClass("scrollRight");
	}
	clearTimeout(v);
}

