//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::://
//	Link/Banner Carousel
//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::://
// Handles the link banner functionality for SpriteArt.com. Loads either js data or XML (yet unknown based on necessity) and creates a
// cyclical carousel of links available, in random order (non-repetitive)

	var BANNER_LIST = new Array();
	var BANNER_INDEX; 
	var CURRENT_LINK = false;
	var PREVIOUS_LINK = false;
	var SIZE = 8; 
	// initiate banner list (note this is not a user-submitted friendly code snippet, may change in the future
	// assumes banners are all of a common size
	function Init_Banner(){
			Slide_Object_Offset(document.getElementById('link_bg'), 'right', 100, 6, 10, 1.04); 
			Clock_Counter()();	
			Init_BannerList(6);
	}
	
	function Init_BannerList(delay){
			var src_base = 'art/links/';
			var src;
			var href;
			var tag;
			for (var i = 0 ; i < SIZE; i++){
					switch (i){
							case 0:		src = src_base+'01.gif';
										href = 'http://www.kennethfejer.com';
										tag  = 'kenneth fejer';
										break;
							case 1:		src = src_base+'02.gif';
										href = 'http://www.pixeljoint.com';
										tag  = 'pixel joint';
										break;
							case 2:		src = src_base+'04.gif';
										href = 'http://www.finalredemption.com/index';
										tag  = 'final redemption';
										break;
							case 3:		src = src_base+'05.gif';
										href = 'http://www.gas13.ru';
										tag  = 'gas 13';
										break;
							case 4:		src = src_base+'06.gif';
										href = 'http://pixelstamps.gas13.ru/';
										tag  = 'pixel stamps';
										break;
							case 5: 	src = src_base+'07.gif';
										href='http://www.spiv.cz/index.html';
										tag = 'spiv';
										break;
							case 6:		src = src_base+'08.gif';
										href='http://www.paxjah.com/en_happyflava/index_blue.html';
										tag = 'happy flava';
							default: 	break;
					}
					// create new array with appropriate information
					var this_link = new Array();
					this_link.push(src, href, tag);
					// append this to the banner array (2d array)
					BANNER_LIST.push(this_link);
			}
			Cycle_Banner();								// Initialize the first random banner to be displayed
			Cycle_Banner_Timer(delay)();				// begins counter which will trigger subsequent banner cycles
	}
	
	var BANNER_INTERVAL = 10; 							// determines how fast, in seconds, the banner will cycle (default value of 10!)
	var BANNER_COUNTER;									// remembers the previous second hand value at which the banner has last cycled
	var PAUSE_BANNER_CYCLE = true;
	function Cycle_Banner_Timer(delay){
			// polling recursion (delay to 1 cycle per second)
			return function() {
					// sets delay value of the interval to cycle banner (in seconds)
					if (delay)	{BANNER_INTERVAL = delay;}
					// check seconds value on clock
					var secs =  USER_SECS;	
					if (!BANNER_COUNTER)	{BANNER_COUNTER = secs;}					// first cycle initialization
			
					var secs_adjusted = (secs < BANNER_COUNTER) ? secs+60 : secs;		// account for when second timer loops back to 0
					if (secs_adjusted == BANNER_COUNTER+BANNER_INTERVAL){
							BANNER_COUNTER = secs;										// reinitialize previous counter start point
							if (PAUSE_BANNER_CYCLE)	{Cycle_Banner();}
																			// will change elements on page dynamically to reflect banner cycle change
					}
					setTimeout(Cycle_Banner_Timer(), 1000);
			}
	}
	
	function Cycle_Banner(){
			// randmonly seed a number between 0 and BANNER_LIST.length
			var seed = Math.floor(Math.random() * 100);
			var index = seed % BANNER_LIST.length; 
			// remove possibility of duplicate links displaying sequentially
			if (index == BANNER_INDEX){
					index = (index-1 < 0) ? index+1 : index-1;
			}
			// if old link exists, move image down out of view
			if (CURRENT_LINK){
					Slide_Object_Offset(CURRENT_LINK, 'down', 32, 2, 30, 1.10);
					FadeOpacity(CURRENT_LINK, 0, 100, 10);
					// kill previous link element and reassign current link as previous
					if (PREVIOUS_LINK)	{document.getElementById('link_frame').removeChild(PREVIOUS_LINK);}
					PREVIOUS_LINK = CURRENT_LINK; 	
			}
			
			// create new image element based on random index 
			var new_link = document.createElement('div');
				new_link.className = "banner_img";
				new_link.id = BANNER_LIST[index][2];
					new_link.style.backgroundImage = "URL('"+BANNER_LIST[index][0]+"')";
					new_link.style.top = '-32px';
					new_link.style.left= '0px';
			CURRENT_LINK = new_link; 
			BANNER_INDEX = index;
			document.getElementById('link_frame').appendChild(new_link);
					
			// slide link into view 
			Slide_Object_Offset(new_link, 'down', 32, 2, 30, 1.10);
			FadeOpacity(new_link, 100, 10, 5);
			Float_Banner_Tag();
	}
	
	var CURRENT_BANNER_TAG;
	var PREVIOUS_BANNER_TAG;
	function Float_Banner_Tag(){
			// if previous tag exists, float it off the screen,
			if (CURRENT_BANNER_TAG){
					Slide_Object_Offset(CURRENT_BANNER_TAG, 'right', 96, 4, 20, 1.04);
					FadeOpacity(CURRENT_BANNER_TAG, 0, 100, 5, 5);
					// remove previous banner object from stack to avoid leak
					if (PREVIOUS_BANNER_TAG){
							document.getElementById('link_tag').removeChild(PREVIOUS_BANNER_TAG);
					}
					PREVIOUS_BANNER_TAG = CURRENT_BANNER_TAG;
			}
			
			//create new div element to house text
			var tag = document.createElement('div');
				tag.className='banner_tag';
				tag.id='banner'+BANNER_INDEX;
				tag.innerHTML = BANNER_LIST[BANNER_INDEX][2];
				tag.style.left = '-96px';
			document.getElementById('link_tag').appendChild(tag);
			CURRENT_BANNER_TAG = tag;
			// float new tag on screen and reassign to current
			Slide_Object_Offset(CURRENT_BANNER_TAG, 'right', 96, 4, 20, 1.06);
	}
	
			function Follow_Link(){
					window.status = BANNER_LIST[BANNER_INDEX][1];
					window.location.href = BANNER_LIST[BANNER_INDEX][1];
			}
			
			function Toggle_Banner_Active(){
					if (PAUSE_BANNER_CYCLE)	{PAUSE_BANNER_CYCLE = false;}
					else 					{PAUSE_BANNER_CYCLE = true;}
			}
			
	function Toggle_Banner_Tag(bool_visible){
			// shows text title of link banner when hilighted
			var fade_to   = (bool_visible) ? 100 : 0;
			var fade_from = (bool_visible) ? 0 : 100;
			//call to fade tag in or out
			FadeOpacity(document.getElementById('link_tag'), fade_to, fade_from, 10, 5);
	}
