
// '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_3_page18
// ---------------------------------------------------------------------

// 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_3_page18 = {};

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

	// When jQuery is used it will be available as $ and jQuery but only
	// inside the closure.
	var jQuery = stacks.jQuery;
	var $ = jQuery;
	
jQuery(document).ready(function(){
	jQuery('body').prepend(jQuery('#pageFlipStackstacks_in_3_page18'));
	var theMSGImageURL=jQuery('.msg_block img').attr('src');
	var theMSGImageHeight=jQuery('.msg_block img').attr('height');
	var theMSGImageWidth=jQuery('.msg_block img').attr('width');
	jQuery('.msg_block').empty().css('backgroundImage', 'url('+theMSGImageURL+')');
	var thePos='left';
	if (thePos=='right') {
		jQuery('#pageFlipStackstacks_in_3_page18 img.flipImage').attr('src','files/pageFlip_right.png');
		jQuery('#pageFlipStackstacks_in_3_page18 img.flipImage , .msg_block').css({
			right: 0
		});
		jQuery('.msg_block').css('backgroundPosition', 'top right');
	}
	else {
		jQuery('#pageFlipStackstacks_in_3_page18 img.flipImage').attr('src','files/pageFlip_left.png');
		jQuery('#pageFlipStackstacks_in_3_page18 img.flipImage , .msg_block').css({
			left: 0
		});
		jQuery('.msg_block').css('backgroundPosition', 'top left');
	}
	jQuery("#pageFlipStackstacks_in_3_page18").hover(function() {
	 //On hover...
	jQuery("#pageFlipStackstacks_in_3_page18 img.flipImage").stop()
		.animate({ //Animate and expand the image and the msg_block (Width + height)
			width: theMSGImageWidth,
			height: theMSGImageHeight
		}, 500);
	jQuery(".msg_block").stop()
		.animate({ //Animate and expand the image and the msg_block (Width + height)
			width: theMSGImageWidth,
			height: theMSGImageHeight*0.96
		}, 500);
	} , function() {
	jQuery("#pageFlipStackstacks_in_3_page18 img.flipImage").stop() //On hover out, go back to original size 50x52
		.animate({
			width: '50px',
			height: '52px'
		}, 220);
	jQuery(".msg_block").stop() //On hover out, go back to original size 50x50
		.animate({
			width: '50px',
			height: '50px'
		}, 200); //Note this one retracts a bit faster (to prevent glitching in IE)
});

});
	return stack;
})(stacks.stacks_in_3_page18);


// Javascript for stacks_in_5_page18
// ---------------------------------------------------------------------

// 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_5_page18 = {};

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

	// When jQuery is used it will be available as $ and jQuery but only
	// inside the closure.
	var jQuery = stacks.jQuery;
	var $ = jQuery;
	
function setCookie(name,value,days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime()+(days*60*60*1000));
        var expires = "; expires="+date.toGMTString();
    }
    else var expires = "";
    document.cookie = name+"="+value+expires ;
}

function getCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
}

function deleteCookie(name) {
    setCookie(name,"");
}


$(document).ready(function() {



// Get lz cookie
var cooky = getCookie('doo_lz_cookie_set');

 // Create the new lz cookie and store it for 1 day
setCookie('doo_lz_cookie_set', 'lzcookyset', 1);

$("#stacks_in_5_page18").css("margin" , 0);
var orgonal = $("#stacks_in_5_page18");
var slidedelay = (3000) ;
var slidespeed = (2000) ;

var position = $("#stacks_in_5_page18").offset();

if (cooky == "lzcookyset"){
$("#stacks_in_5_page18").remove();
}

if (cooky != "lzcookyset"){
  
   
$("<div/>", {
  "class": "doosuperoverlay"
})
.prependTo("body")
.delay(2000)
.fadeOut(2000);


var orgStackWidth = $("#stacks_in_5_page18").width();
var tempClone = $("#stacks_in_5_page18").clone();
$(tempClone).css({
"position" : "relative",
"width" : orgStackWidth + "px",
"text-align" : "left"
});

$(tempClone).fadeIn(1000).appendTo(".doosuperoverlay").css(position)
.delay(2000)
.fadeOut(2000);
  // showstack once
var dooremoveoverlaytimer = 2000 + 2000 + 500;
setTimeout(function(){ $('.doosuperoverlay').remove(); }, dooremoveoverlaytimer);

}  // end if cookie exists

$(orgonal).delay(slidedelay).slideUp(slidespeed);;

 
$('.lzeffect').remove();



if("$(orgonal).delay(slidedelay).slideUp(slidespeed);" != ""){
var doodelaylz = slidedelay + slidespeed + 1000 + 2000 + 2000;
setTimeout(function(){ $("#stacks_in_5_page18").remove(); }, doodelaylz + 1000);
}

});


	return stack;
})(stacks.stacks_in_5_page18);


// Javascript for stacks_in_17_page18
// ---------------------------------------------------------------------

// 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_17_page18 = {};

// A closure is defined and assigned to the stack's object.  The object
// is also passed in as 'stack' which gives you a shorthand for referring
// to this object from elsewhere.
stacks.stacks_in_17_page18 = (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(){
            

$.fn.reverseOrder = function() {
	return this.each(function() {
		$(this).prependTo( $(this).parent() );
	});
};





            $('#stacks_in_17_page18 .listContainer').hover(function(){
					$(".sliderBox", this).stop().animate({top:'-60px'},{queue:false,duration:100});
				}, function() {
					$(".sliderBox", this).stop().animate({top:'0px'},{queue:false,duration:300});
                       
            });
                
                

               
               

       
});
            
     

 

	return stack;
})(stacks.stacks_in_17_page18);


// Javascript for stacks_in_50_page18
// ---------------------------------------------------------------------

// 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_50_page18 = {};

// A closure is defined and assigned to the stack's object.  The object
// is also passed in as 'stack' which gives you a shorthand for referring
// to this object from elsewhere.
stacks.stacks_in_50_page18 = (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(){
            

$.fn.reverseOrder = function() {
	return this.each(function() {
		$(this).prependTo( $(this).parent() );
	});
};





            $('#stacks_in_50_page18 .listContainer').hover(function(){
					$(".sliderBox", this).stop().animate({top:'-60px'},{queue:false,duration:100});
				}, function() {
					$(".sliderBox", this).stop().animate({top:'0px'},{queue:false,duration:300});
                       
            });
                
                

               
               

       
});
            
     

 

	return stack;
})(stacks.stacks_in_50_page18);


// Javascript for stacks_in_81_page18
// ---------------------------------------------------------------------

// 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_81_page18 = {};

// A closure is defined and assigned to the stack's object.  The object
// is also passed in as 'stack' which gives you a shorthand for referring
// to this object from elsewhere.
stacks.stacks_in_81_page18 = (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 Select Stack v1.5.1 by Joe Workman --//

//---------------------------
// 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)) {
        var mylink = obj.link[0].href;
        $.each(obj.link,function(index, value){
            if (value.rel === 'alternate') {
                mylink = value.href;
            }
		})
        return mylink;
    }
    else if (typeof obj.link == 'object') {
        return obj.link.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;
};
//---------------------------
// End Common RSS Code
//---------------------------

var $totalTabs=0;
var $tabs = new Object;
$(document).ready(function() {

    $(".rss_feed").each(function() {
        var $title = $(this).attr('feed:title');
        var $url   = $(this).attr('feed:url');

        var $obj = new Object;
        $obj["feed"] = $url;

        $tabs[$title] = $obj;
        /* Count the tabs */
        $totalTabs++;
    });	

	$('#feedWidget').show().mouseleave(function(){
		/* If the cursor left the widet, hide the drop down list: */
		$('.dropDownList').remove();
		$('#activeTab').removeClass('hover');
	}).mouseenter(function(){
		if($totalTabs>1) $('#activeTab').addClass('hover');
	});

	$('#activeTab').click(showDropDown);

	/* Using the live method to bind an event, because the .dropDownList does not exist yet: */
	$('.dropDownList div').live('click',function(){
		/* Calling the showDropDown function, when the drop down is already shown, will hide it: */
		showDropDown();
		showTab($(this).text());
	});
	
	var $show_first = $(".rss_feed:first").attr('feed:title');
    showTab($show_first);
});

function add_feed_item(obj) {
    var maxLength = 150;
	$('#tabContent').append('<div><p class="rss-title">' + find_title(obj) +
		'</p><p class="rss-date">'+ find_date(obj) + 
		'</p><p class="rss-desc">' + find_descr(obj).substring(0, maxLength) +
		'...</p><a class="tiptip"  title="' + find_date(obj) + 
		' - ' + find_descr(obj).substring(0, maxLength) + '" href="' + find_link(obj) + 
		'" target="_self">[read]</a></div>'
	);
	if ($().tipTip) { $(".tiptip").tipTip(); }
	return;    	        
};

function showTab(key) {
	var obj = $tabs[key];
	if(!obj) return false;
	
	/* Forming the query: */
	var feed = obj.feed;
	feed = feed.replace(/feed:\/\//,'http://'); // Replace feed:// with http://
	var query = 'select * from feed where url="' + feed + '" LIMIT 3';
	
	/* Forming the URL to YQL: */
	var url = "http://query.yahooapis.com/v1/public/yql?q="+encodeURIComponent(query)+"&format=json&callback=?";

	$.getJSON(url,function(data){
		$('#tabContent').empty();
		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);
		}
	});
	$('#activeTab').text(key);
};

function showDropDown() {
	if($totalTabs<2) return false;
	
	if($('#feedWidget .dropDownList').length)
	{
		/* If the drop down is already shown, hide it: */
		$('.dropDownList').slideUp('fast',function(){ $(this).remove(); })
		return false;
	}
	
	var activeTab = $('#activeTab');
	var offsetTop = (activeTab.offset().top - $('#feedWidget').offset().top )+activeTab.outerHeight() - 5;
	
	/* Creating the drop down div on the fly: */
	var dropDown = $('<div>').addClass('dropDownList').css({
			'top'	: offsetTop,
			'width'	: activeTab.width()
	}).hide().appendTo('#feedWidget')
	
	$.each($tabs,function(j){
		/* Populating the div with the tabs that are not currently shown: */
		if(j==activeTab.text()) return true;
		$('<div>').text(j).appendTo(dropDown);
	})
	
	dropDown.slideDown('fast');
};
//-- End RSS Select Stack --//


	return stack;
})(stacks.stacks_in_81_page18);



