
// 'stacks' is the Stacks global object.
// All of the other Stacks related Javascript will 
// be attatched to it.
var stacks = {};


// this call to jQuery gives us access to the globaal
// jQuery object. 
// 'noConflict' removes the '$' variable.
// 'true' removes the 'jQuery' variable.
// removing these globals reduces conflicts with other 
// jQuery versions that might be running on this page.
stacks.jQuery = jQuery.noConflict(true);

// Javascript for stacks_in_1_page24
// ---------------------------------------------------------------------

// Each stack has its own object with its own namespace.  The name of
// that object is the same as the stack's id.
stacks.stacks_in_1_page24 = {};

// A closure is defined and assined to the stack's object.  The object
// is also passed in as 'stack' which gives you a shorthand for refering
// to this object from elsewhere.
stacks.stacks_in_1_page24 = (function(stack) {

	// When jQuery is used it will be available as $ and jQuery but only
	// inside the closure.
	var jQuery = stacks.jQuery;
	var $ = jQuery;
	
$(document).ready(function() {
	var custom_bg_src = $("#stacks_in_1_page24 .custom_bg img").attr("src");
	if (custom_bg_src) { $("#stacks_in_1_page24").css({'background-image':'url(' + custom_bg_src + ')'});	}
});
	return stack;
})(stacks.stacks_in_1_page24);


// Javascript for stacks_in_4_page24
// ---------------------------------------------------------------------

// Each stack has its own object with its own namespace.  The name of
// that object is the same as the stack's id.
stacks.stacks_in_4_page24 = {};

// A closure is defined and assined to the stack's object.  The object
// is also passed in as 'stack' which gives you a shorthand for refering
// to this object from elsewhere.
stacks.stacks_in_4_page24 = (function(stack) {

	// When jQuery is used it will be available as $ and jQuery but only
	// inside the closure.
	var jQuery = stacks.jQuery;
	var $ = jQuery;
	
//-- Gyro Stack v1.2 by Joe Workman --//

$(document).ready(function() {

	// Create the ribbon HTML
	createPager = function(){	
        $("#stacks_in_4_page24 .gyro_image_reel img").each(function(index) {
            $('<a href="#" rel="' + (index+1) + '">' + (index+1) + '</a>').appendTo('#stacks_in_4_page24 div.gyro_ribbon_middle');
        });
		// Need to swap the bragrounds when the ribbon is on the left
		if ('right' == 'left') {
			$('#stacks_in_4_page24 .gyro_ribbon_start').css("background", "url('rw_common/plugins/stacks/images/ribbon0/gyro_ribbon_right_end_0.png') no-repeat");
			$('#stacks_in_4_page24 .gyro_ribbon_end').css("background", "url('rw_common/plugins/stacks/images/ribbon0/gyro_ribbon_right_start_0.png') no-repeat");			
		}
		// This is to set some CSS styles for ribbons that don't  fit into the defaults set in the CSS file
		/* if ('0' == 2 || '0' == 3 || '0' == 4) {
			$('#stacks_in_4_page24 .gyro_ribbon').css("right", "-13px");
		}
		if ('0' == 5 || '0' == 6) {
			$('#stacks_in_4_page24 .gyro_ribbon_end').css("width", "32px");
		} */
	}; 
	createPager(); //Run function on launch

	//Set Default State of each portfolio piece
	 $("#stacks_in_4_page24 .gyro_ribbon").show();
	$("#stacks_in_4_page24 .gyro_ribbon a:first").addClass("active");

	//Get size of images, how many there are, then determin the size of the image reel.
	var imageHeight = $("#stacks_in_4_page24 .gyro_image_reel img:first").height();
	var imageWidth = $("#stacks_in_4_page24 .gyro_image_reel img:first").width();
	var imageSum = $("#stacks_in_4_page24 .gyro_image_reel img").size();
	var imageReelWidth = imageWidth * imageSum;
	
	//Adjust the image reel to its new size
	$("#stacks_in_4_page24 .gyro_container").css({'width' : imageWidth});
	$("#stacks_in_4_page24 .gyro_window").css({'width' : imageWidth});
	$("#stacks_in_4_page24 .gyro_window").css({'height' : imageHeight});
	$("#stacks_in_4_page24 .gyro_image_reel").css({'width' : imageReelWidth});
			
	//ribbon + Slider Function
	rotate = function(){	
		var triggerID = $active.attr("rel") - 1; //Get number of times to slide
		var image_reelPosition = triggerID * imageWidth; //Determines the distance the image reel needs to slide

		$("#stacks_in_4_page24 .gyro_ribbon a").removeClass('active'); //Remove all active class
		$active.addClass('active'); //Add active class (the $active is declared in the rotateSwitch function)
		
		//Slider Animation
		$("#stacks_in_4_page24 .gyro_image_reel").animate({ 
			left: -image_reelPosition
		}, 1000 );		
	}; 
	
	var play;
	//Rotation + Timing Event
	rotateSwitch = function(){		
		play = setInterval(function(){ //Set timer - this will repeat itself every 3 seconds
			$active = $('#stacks_in_4_page24 .gyro_ribbon a.active').next();
			if ( $active.length === 0) { //If ribbon reaches the end...
				$active = $('#stacks_in_4_page24 .gyro_ribbon a:first'); //go back to first
			}
			rotate(); //Trigger the ribbon and slider function
		}, 6039); //Timer speed in milliseconds
	};
	rotateSwitch(); //Run function on launch
	
	//On Hover
	$("#stacks_in_4_page24 .gyro_image_reel a").hover(function() {
		clearInterval(play); //Stop the rotation
	}, function() {
		rotateSwitch(); //Resume rotation
	});	

	//On Click
	$("#stacks_in_4_page24 .gyro_ribbon a").click(function() {	
		$active = $(this); //Activate the clicked ribbon
		//Reset Timer
		clearInterval(play); //Stop the rotation
		rotate(); //Trigger rotation immediately
		if (false) {
			clearInterval(play); //Stop the rotation
		}
		else {
			rotateSwitch(); // Resume rotation
		}
		return false; //Prevent browser jump to link anchor
	});	
});

//-- End Gyro Stack --//
	return stack;
})(stacks.stacks_in_4_page24);


// Javascript for stacks_in_22_page24
// ---------------------------------------------------------------------

// Each stack has its own object with its own namespace.  The name of
// that object is the same as the stack's id.
stacks.stacks_in_22_page24 = {};

// A closure is defined and assined to the stack's object.  The object
// is also passed in as 'stack' which gives you a shorthand for refering
// to this object from elsewhere.
stacks.stacks_in_22_page24 = (function(stack) {

	// When jQuery is used it will be available as $ and jQuery but only
	// inside the closure.
	var jQuery = stacks.jQuery;
	var $ = jQuery;
	

//-- RSS Fader Stack v1.2 by Joe Workman --//

/****** Start NewTicker JQuery plugin
 * Copyright (c) 2006/2007 Sam Collett (http://www.texotela.co.uk)
 * Licensed under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 * Version 2.0
 * Demo: http://www.texotela.co.uk/code/jquery/newsticker/
 *
 * I have modified this plugin slightly to support TipTip Integration */
(function($) { $.fn.newsTicker = $.fn.newsticker = function(delay) { delay = delay || 4000; initTicker = function(el) { stopTicker(el); el.items = $("li", el); el.items.not(":eq(0)").hide().end(); el.currentitem = 0; startTicker(el); }; startTicker = function(el) { el.tickfn = setInterval(function() { doTick(el) }, delay) }; stopTicker = function(el) { clearInterval(el.tickfn); }; pauseTicker = function(el) { el.pause = true; }; resumeTicker = function(el) { el.pause = false; }; doTick = function(el) { if(el.pause) return; el.pause = true; $(el.items[el.currentitem]).fadeOut("slow", function() { $(this).hide(); el.currentitem = ++el.currentitem % (el.items.size()); $(el.items[el.currentitem]).fadeIn("slow", function() { el.pause = false; } ); } ); }; this.each( function() { if(this.nodeName.toLowerCase()!= "ul") return; initTicker(this); } ) .addClass("newsticker") .hover( function() { pauseTicker(this); if ($().tipTip) { $(".tiptip").tipTip(); } }, function() { resumeTicker(this); } ); return this; };})(jQuery);

//---------------------------
// Start Common RSS Code
//---------------------------
formatString = function(str) {
	str = str.replace(/<[^>]+>/ig,'');
	str=' '+str;
	return $.trim(str);
}

enrichString = function(str) {
	str = str.replace(/((ftp|https?):\/\/([-\w\.]+)+(:\d+)?(\/([\w/_\.]*(\?\S+)?)?)?)/gm,'<a href="$1" target="_blank">$1</a>');
	str = str.replace(/([^\w])\@([\w\-]+)/gm,'$1@<a href="http://twitter.com/$2" target="_blank">$2</a>');
	str = str.replace(/([^\w])\#([\w\-]+)/gm,'$1<a href="http://twitter.com/search?q=%23$2" target="_blank">#$2</a>');
	return $.trim(str);
}

parse_date = function(str) {
    if (str.match(/^\d+\-\d+\-\d+T/)) {
        str = str.replace(/T.+$/,'');
    }
	var d = new Date(str);
	var m = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'June', 'July', 'Aug', 'Sept', 'Oct', 'Nov', 'Dec'];
	if (d.getUTCDate()) {
		return d.getUTCDate() + ' ' + m[d.getUTCMonth()] + ' ' + d.getFullYear();
    }
    return str;
};

find_link = function(obj) {
    var default_string = '#';
    if (obj == null || obj == undefined) {
        return default_string;
    }	
    else if (typeof obj.origLink == 'string') {
        return obj.origLink;
    }
    else if ($.isArray(obj.link)) {
        return obj.link[0].href;
    }
    else if (typeof obj.link == 'string') {
        return obj.link;
    }
    else if (typeof obj.enclosure == 'object' && typeof obj.enclosure.url == 'string') {
        return obj.enclosure.url;
    }
    return default_string;
};

find_title = function(obj) {
    var default_string = 'No Items in RSS Feed';
    if (obj == null || obj == undefined) {
        return default_string;
    }	
    else if (typeof obj.title.content == 'string') {
        return formatString(obj.title.content);
    }
    else if (typeof obj.title == 'string') {
        return formatString(obj.title);
    }
    return default_string;
};

find_date = function(obj) {
    var default_string = 'Date Unknown';
    if (obj == null || obj == undefined) {
        return default_string;
    }	
    else if (typeof obj.pubDate == 'string') {
		return parse_date(obj.pubDate);
    }
    else if (typeof obj.date == 'string') {
		return parse_date(obj.date);
    }
    else if (typeof obj.published == 'string') {
		return parse_date(obj.published);
    }
    else if (typeof obj.updated == 'string') {
		return parse_date(obj.updated);
    }
    return default_string;
};

find_descr = function(obj) {
    var default_string = 'RSS Feed Invalid. No Description Found.';
    if (obj == null || obj == undefined) {
        return default_string;
    }	
    else if (typeof obj.description == 'string') {
		return formatString(obj.description);
    }
    else if (typeof obj.encoded == 'string') {
		return formatString(obj.encoded);
    }
    else if (typeof obj.content == 'object' && typeof obj.content.content == 'string') {
		return formatString(obj.content.content);
    }
    return default_string;
};

find_author = function(obj) {
    var default_string = 'Unknown Author';
    if (obj == null || obj == undefined) {
        return default_string;
    }	
    else if (typeof obj.creator == 'string') {
		return obj.creator;
    }
    else if ($.isArray(obj.author)) {
        return obj.author[0];
    }
    else if (typeof obj.author == 'object' && typeof obj.author.email == 'string') {
		return obj.author.email;
    }
    else if (typeof obj.author == 'string') {
		return obj.author;
    }
    return default_string;
};

$(document).ready(function() {
	/* Forming the query: */
	var feed = "feed://www.jopgv.nl/milieu/files/blog.xml";
	feed = feed.replace(/feed:\/\//,'http://'); // Replace feed:// with http://
	var query = 'select * from feed where url="' + feed + '" LIMIT 10';

	/* Forming the URL to YQL: */
	var url = "http://query.yahooapis.com/v1/public/yql?q="+encodeURIComponent(query)+"&format=json&callback=?";

	$.getJSON(url,function(data){
		if (data.query == null || data.query == undefined || data.query.results == null || data.query.results == undefined) {
			// Invalid or Empty RSS Feed - Add Blank/Default Entries
			add_feed_item();
	 	}
	 	else if ($.isArray(data.query.results.item || data.query.results.entry) ) {  //item exists in RSS and entry in ATOM feeds
			$.each(data.query.results.item || data.query.results.entry,function(){
	       		//Normal RSS Feed
	       		add_feed_item(this);
			})
		}
		else {
		    // RSS Feed with only one item in it
			add_feed_item(data.query.results.item || data.query.results.entry || null);
		}
		post_process_feed(this);
	});
});
//---------------------------
// End Common RSS Code
//---------------------------

function add_feed_item(obj) {
    var maxLength = 150;
	$('#rss-fader-list-stacks_in_22_page24').append('<li><a class="tiptip" title="' + find_date(obj) + 
	  	' - ' + find_descr(obj).substring(0, maxLength) +
		'" href="' + find_link(obj) +
		'" target="_self">' + find_title(obj) + '</a></li>'
	);
    $('#rss-fader-list-stacks_in_22_page24').newsTicker();
	return;    	        
};
function post_process_feed(obj) {
	return;    	        
};
//-- End RSS Fader Stack --//


	return stack;
})(stacks.stacks_in_22_page24);


// Javascript for stacks_in_42_page24
// ---------------------------------------------------------------------

// Each stack has its own object with its own namespace.  The name of
// that object is the same as the stack's id.
stacks.stacks_in_42_page24 = {};

// A closure is defined and assined to the stack's object.  The object
// is also passed in as 'stack' which gives you a shorthand for refering
// to this object from elsewhere.
stacks.stacks_in_42_page24 = (function(stack) {

	// When jQuery is used it will be available as $ and jQuery but only
	// inside the closure.
	var jQuery = stacks.jQuery;
	var $ = jQuery;
	
$(document).ready(function() {
	var custom_bg_src = $("#stacks_in_42_page24 .custom_bg img").attr("src");
	if (custom_bg_src) { $("#stacks_in_42_page24").css({'background-image':'url(' + custom_bg_src + ')'});	}
});
	return stack;
})(stacks.stacks_in_42_page24);


// Javascript for stacks_in_55_page24
// ---------------------------------------------------------------------

// Each stack has its own object with its own namespace.  The name of
// that object is the same as the stack's id.
stacks.stacks_in_55_page24 = {};

// A closure is defined and assined to the stack's object.  The object
// is also passed in as 'stack' which gives you a shorthand for refering
// to this object from elsewhere.
stacks.stacks_in_55_page24 = (function(stack) {

	// When jQuery is used it will be available as $ and jQuery but only
	// inside the closure.
	var jQuery = stacks.jQuery;
	var $ = jQuery;
	
$(document).ready(function() {
	var custom_bg_src = $("#stacks_in_55_page24 .custom_bg img").attr("src");
	if (custom_bg_src) { $("#stacks_in_55_page24").css({'background-image':'url(' + custom_bg_src + ')'});	}
});
	return stack;
})(stacks.stacks_in_55_page24);


// Javascript for stacks_in_68_page24
// ---------------------------------------------------------------------

// Each stack has its own object with its own namespace.  The name of
// that object is the same as the stack's id.
stacks.stacks_in_68_page24 = {};

// A closure is defined and assined to the stack's object.  The object
// is also passed in as 'stack' which gives you a shorthand for refering
// to this object from elsewhere.
stacks.stacks_in_68_page24 = (function(stack) {

	// When jQuery is used it will be available as $ and jQuery but only
	// inside the closure.
	var jQuery = stacks.jQuery;
	var $ = jQuery;
	
$(document).ready(function() {
	var custom_bg_src = $("#stacks_in_68_page24 .custom_bg img").attr("src");
	if (custom_bg_src) { $("#stacks_in_68_page24").css({'background-image':'url(' + custom_bg_src + ')'});	}
});
	return stack;
})(stacks.stacks_in_68_page24);


