So, I am trying to make it so I can create a variable globally throughout my whole document with jQuery, but inside of an .each() statement.
Where I put "var previous = item.channel.display_name" is the variable I am trying to create.
Code:
jQuery(function(){
var streams = null;
jQuery.getJSON("https://api.twitch.tv/kraken/search/streams?q=path%20of%20exile&callback=?", function (data) {
streams = data.streams;
jQuery("#next").show();
jQuery("#prev").show();
jQuery("#next").click();
});
var globalCnt = 0;
jQuery("#next").click(function() {
var localCnt = 0;
var itemsToShow = 1;
jQuery.each(streams, function (index, item) {
localCnt++;
if(localCnt > globalCnt && itemsToShow > 0) {
jQuery("#content").empty();
jQuery("#content").html('<object style="margin-left:0.5%;" type="application/x-shockwave-flash" height="378" width="620" id="live_embed_player_flash" data="http://www.twitch.tv/widgets/live_embed_player.swf?channel=' + item.channel.display_name + '" bgcolor="#000000"><param name="allowFullScreen" value="true" /><param name="allowScriptAccess" value="always" /><param name="allowNetworking" value="all" /><param name="movie" value="http://www.twitch.tv/widgets/live_embed_player.swf" /><param name="flashvars" value="hostname=www.twitch.tv&channel=' + item.channel.display_name + '&auto_play=false&start_volume=25" /></object><iframe frameborder="0" scrolling="no" id="chat_embed" src="http://twitch.tv/chat/embed?channel=' + item.channel.display_name +'&popout_chat=true" height="378" width="350"></iframe>');
globalCnt++;
itemsToShow--;
var previous = item.channel.display_name;
}
});
if(itemsToShow > 0)
jQuery("#showBtn").hide();
});
jQuery("#prev").click(function() {
var localCnt = 0;
var itemsToShow = 1;
jQuery.each(streams, function (index, item) {
localCnt++;
if(localCnt > globalCnt && itemsToShow > 0) {
jQuery("#content").empty();
document.write(previous);
jQuery("#content").html('<object style="margin-left:0.5%;" type="application/x-shockwave-flash" height="378" width="620" id="live_embed_player_flash" data="http://www.twitch.tv/widgets/live_embed_player.swf?channel=' + previous + '&auto_play=false&start_volume=25" /></object><iframe frameborder="0" scrolling="no" id="chat_embed" src="http://twitch.tv/chat/embed?channel=' + previous +'&popout_chat=true" height="378" width="350"></iframe>');
globalCnt++;
itemsToShow--;
}
});
if(itemsToShow > 0)
jQuery("#showBtn").hide();
});
});