
	/*	recirculation feed functions	*/
	//	global variable initialization
	var MasterArray = new Array();
/* 	global Partner Recirc function */
	var PartnerRecirc = function() {
		var arr = MasterArray;
		var nextFeed;
		var recircCallback = function(pos) {
			if (!document.getElementById) return;
			if (!document.getElementById(pos.id)) return;
			divID = pos.name.replace(/\./,'').replace(/ /,'');
			var	divHTML = '<div class="partnertout clear">';	
			divHTML += '	<h6 class="'+ pos.class +'" title="From '+ pos.name + '"><a href="' + pos.site + '">From ' + pos.name + '</a></h6>';
			if (pos.response[0][0].imgSrc != '') {
				divHTML += '	<div class="phototout clear">\n';
				divHTML += '    <p class="recircimg"><img src="'+ pos.response[0][0].imgSrc + '" alt="" width="75" border="0" height="75"></p>\n';
			} else {
				divHTML += '	<div class="texttout clear">\n';
			}	
				divHTML += '	<div class="recirclinks">\n';
				divHTML += '		<ul>\n';
				for (li = 0; li < pos.display; li++) {
					if (pos.response[0][li].title != '') {
						divHTML += '			<li><a href="'+pos.response[0][li].url+'" target="_blank">'+pos.response[0][li].title+'</a></li>\n';
					}
				}
				divHTML += '		</ul>\n';
				divHTML += '	</div>\n';
				divHTML += '</div>\n';
				divHTML += '</div>\n';
				divHTML = document.getElementById(pos.id).innerHTML + divHTML + '\n';
				//alert (divHTML);
			var parent = document.getElementById(pos.id);
				parent.innerHTML = divHTML;
			if (parent.className.indexOf('active') < 0) {parent.className = parent.className + ' active';};
		};
		var checkScript = function(pos) {
			var recircInt = setInterval(function() {
				var name = pos.name.replace(/\./,'').replace(/ /,'');
				if (feed) {
					pos.response = new Array(feed);
					feed = null; detachScript(name); pos.callback(pos);
					//if(nextFeed < lastFeed) { getStarted(); };
					if(nextFeed > 0) { getStarted(); };
					clearInterval(recircInt);
				}
			},500);
		};
		var detachScript = function(name) {
			elem = document.getElementById('recirc'+name);
			elem.parentNode.removeChild(elem);
		};
		var attachScript = function(pos) {
			var name = pos.name.replace(/\./,'').replace(/ /,'');
			var script = document.createElement('script');
				script.setAttribute('type','text/javascript');
				script.setAttribute('language','javascript');
				script.setAttribute('id','recirc'+name);
				script.setAttribute('src',pos.json);
			document.body.appendChild(script);
			checkScript(pos);
		};
		var getStarted = function() {
			nextFeed--;
			if (document.getElementById(arr[nextFeed].id)) {
				arr[nextFeed].callback = (arr[nextFeed].callback) ? arr[nextFeed].callback : recircCallback;
				arr[nextFeed].display = (arr[nextFeed].display) ? arr[nextFeed].display : 3;
				arr[nextFeed].cta = (arr[nextFeed].cta) ? arr[nextFeed].cta : 'More news at '+arr[nextFeed].name;
				attachScript(arr[nextFeed]);
			} else {
				if(nextFeed > 0) { getStarted(); };
			}
		};
		var init = function() {
			if (arr.length > 0) {
				nextFeed = arr.length;
				getStarted();
			}
		};
		init();
	}

//	initialize Partner Recirc feeds on photo channel page
	var initializeGlobalRecirc = function() {
		if (!document.getElementById) return;
		if (!document.getElementsByTagName) return;
		var recircArray = {
			'recircs' : [ 
								{

					'id'		: 'celebrityrecirc',
					'type' 		: 'random',
					'display'	: 3,
					'feed' 		: [ 
						{
			
							'name'  	: 'Total Beauty',
							'json' 		: '/instyle/static/json/totalbeauty/feed.js',
							'site' 		: 'http://www.totalbeauty.com/',
							'class' 	: 'totalbeauty'
						},{
							'name'  	: 'Bellasugar',
							'json' 		: '/instyle/static/json/bellasugar/feed.js',
							'site' 		: 'http://www.beallasugar.com',
							'class' 	: 'bellasugar'
						},{
							'name'  	: 'Stylelist',
							'json' 		: '/instyle/static/json/stylelist/feed.js',
							'site' 		: 'http://www.stylelist.com',
							'class' 	: 'stylelist'
						}
					]
					
				},{

					'id'		: 'beautyrecirc',	
					'type' 		: 'random',
					'display'	: 3,
					'feed' 		: [ 
						{
			
							'name'  	: 'Total Beauty',
							'json' 		: '/instyle/static/json/totalbeauty/feed.js',
							'site' 		: 'http://www.totalbeauty.com/',
							'class' 	: 'totalbeauty'
						},{
							'name'  	: 'Fabsugar',
							'json' 		: '/instyle/static/json/fabsugar/feed.js',
							'site' 		: 'http://www.fabsugar.com',
							'class' 	: 'fabsugar'
						},{
							'name'  	: 'Stylelist',
							'json' 		: '/instyle/static/json/stylelist/feed.js',
							'site' 		: 'http://www.stylelist.com',
							'class' 	: 'stylelist'
						}
					]
					
				},{	// example of how to do random recircs in a single container; to randomize order, but show both, change 'display' to 2
				
					'id'		: 'fashionrecirc',
					'type' 		: 'random',
					'display'	: 1,
					'feed' 		: [ 
						{
			
							'name'  	: 'Total Beauty',
							'json' 		: '/instyle/static/json/totalbeauty/feed.js',
							'site' 		: 'http://www.totalbeauty.com/',
							'class' 	: 'totalbeauty'
						},{
							'name'  	: 'Bellasugar',
							'json' 		: '/instyle/static/json/bellasugar/feed.js',
							'site' 		: 'http://www.beallasugar.com',
							'class' 	: 'bellasugar'
						},{
							'name'  	: 'Stylelist',
							'json' 		: '/instyle/static/json/stylelist/feed.js',
							'site' 		: 'http://www.stylelist.com',
							'class' 	: 'stylelist'
						}
					]
				},{	// example of how to do random recircs in a single container; to randomize order, but show both, change 'display' to 2
				
					'id'		: 'partners',
					'type' 		: 'random',
					'display'	: 2,
					'feed' 		: [ 
						{
			
							'name'  	: 'Total Beauty',
							'json' 		: '/instyle/static/json/totalbeauty/feed.js',
							'site' 		: 'http://www.totalbeauty.com/',
							'class' 	: 'totalbeauty'
						},{
							'name'  	: 'Bellasugar',
							'json' 		: '/instyle/static/json/bellasugar/feed.js',
							'site' 		: 'http://www.beallasugar.com',
							'class' 	: 'bellasugar'
						},{
							'name'  	: 'Stylelist',
							'json' 		: '/instyle/static/json/stylelist/feed.js',
							'site' 		: 'http://www.stylelist.com',
							'class' 	: 'stylelist'
						}
					]
				}
			]
		};
		for (var a = 0; a < recircArray.recircs.length; a++) {
			var tempArray = new Array(recircArray.recircs[a]);
			var last = tempArray[0].feed.length;
			if (tempArray[0].type && tempArray[0].type == 'random') { 
				tempArray[0].feed.sort(function() {return 0.5 - Math.random();}); 
				last = tempArray[0].display;
			}
			for (var f = 0; f < last; f++) {
				var ids = tempArray[0].id.split(',');
				var thisID = (ids.length > 1) ? ids[f] : tempArray[0].id;
				tempArray[0].feed[f].id = thisID;
				MasterArray.push(tempArray[0].feed[f]);
			}
		}
	}
	initializeGlobalRecirc();
//	start recirc feed process
	var startRecircFeeds = function() {
		var n = new PartnerRecirc();
	}
	
//	can list as many functions as you want and the loader below will load them as soon as the page is loaded
	var pageLoadFunctions = function() {
		startRecircFeeds();
	}
	tii_callFunctionOnWindowLoad(pageLoadFunctions);

