function Nob2RunFoo(f, w, h)
{
    document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="'+w+'" height="'+h+'">\n');
    document.write('<param name="allowScriptAccess" value="sameDomain" />\n');
	document.write('<param name="movie" value="'+f+'" />\n');
	document.write('<param name="quality" value="best" />\n');
	document.write('<param name="wmode" value="transparent" />\n');
	document.write('<param name="bgcolor" value="#0E2152" />\n');
	document.write('<embed src="'+f+'" quality="best" wmode="transparent" bgcolor="#0E2152" width="'+w+'" height="'+h+'" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />\n');
    document.write('</object>\n');
}

var ShopNob = {
	maxSlides : 20,
	visibleSlides : 5,
	slideWidth : 50 + 2 + 2,
	images : '',
	arrowLeftD : '',
	arrowRightD : '',
	arrowLeft : '',
	arrowRight : '',
	canvas : null,
	navLeft : null,
	navRight : null,
	position : 1,
	toScroll : 0,
	scrollTimer : null,
	
	init : function(img) {
		this.canvas = document.getElementById('ShopNobSSCanvas');
		this.navLeft = document.getElementById('ssNavLeft');
		this.navRight = document.getElementById('ssNavRight');
		this.images = img;
		this.arrowLeftD = '<img src="'+this.images+'nob-ss-nav-left-d.gif" alt="Previous" />';
		this.arrowRightD = '<img src="'+this.images+'nob-ss-nav-right-d.gif" alt="Next" />';
		this.arrowLeft = '<img src="'+this.images+'nob-ss-nav-left.gif" alt="Previous" />';
		this.arrowRight = '<img src="'+this.images+'nob-ss-nav-right.gif" alt="Next" />';

		this.setNav();
		this.scrollTimer = null;
		
		eval('document.shopNob=this;');
	},
	
	setNav : function() {
		if (this.position == 1) {
			this.navLeft.innerHTML = this.arrowLeftD;
			this.navRight.innerHTML = '<a href="#next" onclick="ShopNob.next();">'+this.arrowRight+'</a>';
		} else if (this.position >= this.maxSlides - this.visibleSlides + 1) {
			this.navLeft.innerHTML = '<a href="#previous" onclick="ShopNob.previous();">'+this.arrowLeft+'</a>';
			this.navRight.innerHTML = this.arrowRightD;
		} else {
			this.navLeft.innerHTML = '<a href="#previous" onclick="ShopNob.previous();">'+this.arrowLeft+'</a>';
			this.navRight.innerHTML = '<a href="#next" onclick="ShopNob.next();">'+this.arrowRight+'</a>';
		}
		
		this.navLeft.style.top = this.navRight.style.top = this.navLeft.style.left = this.navRight.style.right = "0px";
		this.navLeft.style.visibility = this.navRight.style.visibility = "visible";
	},
	
	next : function() {
		if (this.scrollTimer != null) return false;
		
		this.position += 4;
		var left = this.canvas.style.left.replace('px', '');
		this.toScroll = left - (this.slideWidth * 4);
		if (Math.abs(this.toScroll) > this.canvas.scrollWidth - (this.slideWidth * this.visibleSlides)) {
			this.toScroll = -(this.canvas.scrollWidth - (this.slideWidth * this.visibleSlides));
			this.position = this.maxSlides;
		}
		this.scrollTimer = setInterval('document.shopNob.scrollLeft()', 5);
	},
	
	scrollLeft : function() {
		var l = this.canvas.style.left.replace('px', '');
		
		if (l > this.toScroll) {
			this.canvas.style.left = '-'+(Math.abs(l)+9)+'px';
		} else {
			this.canvas.style.left = this.toScroll+'px';
			clearInterval(this.scrollTimer);
			this.setNav();
			this.scrollTimer = null;
		}
	},

	previous : function() {
		if (this.scrollTimer != null) return false;
		
		this.position -= 4;
		var left = this.canvas.style.left.replace('px', '');
		this.toScroll = parseInt(left) + (this.slideWidth * 4);
		if (this.toScroll > 0) {
			this.toScroll = 0;
			this.position = 1;
		}
		this.scrollTimer = setInterval('document.shopNob.scrollRight()', 5);
	},
	
	scrollRight : function() {
		var l = parseInt(this.canvas.style.left.replace('px', ''));
		
		if (l < this.toScroll) {
			this.canvas.style.left = (l+9)+'px';
		} else {
			this.canvas.style.left = this.toScroll+'px';
			clearInterval(this.scrollTimer);
			this.setNav();
			this.scrollTimer = null;
		}
	}
};

var Nob2_SS = {
	slides : new Array(),
	slide_count : null,
	current : 0,
	previous : 0,
	wait : 5,
	autoplay : true,
	paused : false,
	fadeTimer : null,
	slideTimer : null,
	opacity : 0,
	div : null,
	loader : null,
	nav : null,
	image_folder : '',
	
	init : function(nob2_ss, img_folder) {
		if (typeof(nob2_ss) == 'object') {
			for (var n in nob2_ss) {
				var the_img = new Image();
/*				this.alt = 'loading';
				the_img.onload = function() { this.alt = 'loaded'; }; */
				the_img.src = nob2_ss[n].src;
				
				this.slides[this.slides.length] = { img : the_img, href : nob2_ss[n].href, title : nob2_ss[n].title };
			}
		}
		this.slide_count = this.slides.length;
		if (this.slide_count == 0) return;
		
		this.image_folder = img_folder;
		
		this.div = document.getElementById('nob2_ss_wrapper');
		this.loader = document.getElementById('nob2_ss_loader');
		this.nav = document.getElementById('nob2_ss_nav');
		
		this.div.style.display = 'block';
		
		eval('document.nob2_slidshshow=this;');
		this.previous = this.slide_count - 1;
		this.current = -1;
		this.play();
		if (this.slide_count > 1) 
			this.slideTimer = setInterval('document.nob2_slidshshow.play()', this.wait * 1000);
	},
	
	show : function(pos) {
		if (this.fadeTimer != null) return;
		
/*		if (this.slides[pos].img.alt == 'loading') {
			this.loader.style.zIndex = '510';
			this.loader.style.left = '192px';
			this.loader.style.top = '175px';
			while (this.slides[pos].img.alt == 'loading') {}
			this.loader.style.left = '-9999px';
			this.loader.style.top = '-9999px';
		} */
		
		this.previous = this.current;
		this.current = pos - 2;
		this.opecity = 0;
		this.play();
	},
	
	play : function() {
		if (this.fadeTimer != null) return;
		
		this.current++;
		if (this.current == this.slide_count) this.current = 0;
		this.setNav();
		
		var this_slide = document.getElementById('nob2_slide_'+this.current);
		if (!this_slide) {
			this_slide = document.createElement('DIV');
			this_slide.id = 'nob2_slide_'+this.current;
			this_slide.className = 'nob2_ss_slide';
			this_slide.innerHTML = '<h1><a href="'+this.slides[this.current].href+'" title="'+this.slides[this.current].title+'">'+this.slides[this.current].title+'</a></h1><a href="'+this.slides[this.current].href+'" title="'+this.slides[this.current].title+'"><img src="'+this.slides[this.current].img.src+'" title="'+this.slides[this.current].title+'" /></a>';
			this.div.appendChild(this_slide);
		}
		
		for (var i=0; i<this.slide_count; i++) {
			var the_slide = document.getElementById('nob2_slide_'+i);
			if (the_slide) the_slide.style.zIndex = (500 - this.slide_count - i);
		}
		
		var previous_slide = document.getElementById('nob2_slide_'+this.previous);
		if (previous_slide) previous_slide.style.zIndex = '499';
		this.previous = this.current;
		
		this_slide.style.opacity = '0';
		this_slide.style.filter = 'alpha(opacity=0)';
		this_slide.style.zIndex = '500';
		
		this.opacity = 0;
		this.fadeTimer = setInterval('document.nob2_slidshshow.fadeIn()', 1);
	},
	
	pause : function() {
		this.paused = true;
		clearInterval(this.slideTimer);
		this.slideTimer = null;
		this.setNav();
	},
	
	resume : function() {
		this.paused = false;
		this.play();
		this.slideTimer = setInterval('document.nob2_slidshshow.play()', this.wait * 1000);
	},
	
	fadeIn : function() {
		var this_slide = document.getElementById('nob2_slide_'+this.current);
		
		this.opacity += 5;
		if (this.opacity <= 100) {
			this_slide.style.opacity = (this.opacity / 100);
			this_slide.style.filter = 'alpha(opacity='+this.opacity+')';
		} else {
			this.opacity = 0;
			clearInterval(this.fadeTimer);
			this.fadeTimer = null;
		}
	},
	
	setNav : function() {
		if (this.slide_count < 2) return;

		var navHTML = '<dl>';
		navHTML += '<dt>TOP STORIES</dt>';
		for (var i=0; i<this.slide_count; i++) {
			navHTML += '<dd>'
			
			show = i + 1;
			if (show > this.slide_count) show = 0;
			
			if (i == this.current) {
				navHTML += '<span>'+show+'</span>';
			} else {
				navHTML += '<a href="#'+show+'" onclick="Nob2_SS.show('+show+')">'+show+'</a>';
			}
			navHTML += '</dd>'
		}
		if (this.paused == true) {
			navHTML += '<dd><a href="#pause" onclick="Nob2_SS.resume()" title="Resume"><img src="'+this.image_folder+'play.gif" alt="Resume" /></a></dd>';
		} else {
			navHTML += '<dd><a href="#pause" onclick="Nob2_SS.pause()" title="Pause"><img src="'+this.image_folder+'pause.gif" alt="Pause" /></a></dd>';
		}
		navHTML += '</dl>';
		this.nav.innerHTML = navHTML;
		this.nav.style.left = '0px';
		this.nav.style.top = '390px';
	}
}

var RandomAds = {
	ads : null,
	ad_count : 0,
	ad_holders : null,
	
	init : function(ad_obj) {
		this.ads = ad_obj;
		this.ad_count = this.ads.length;
		
		if (this.ad_count == 0) return;
		
		var holders = document.getElementsByTagName('DIV');
		this.ad_holders = new Array();
		for (var i=0; i<holders.length; i++) {
			if (holders[i].id.substr(0, 9) == '_nob2_ad_') {
				this.ad_holders[this.ad_holders.length] = holders[i];
			}
		}
		if (this.ad_holders.length == 0) return;
		
		this.display_ads();
	},
	
	display_ads : function() {
		var unique_randoms = this.get_unique_randoms();
		if (unique_randoms.length == 0) return;
		
		for (var i=0; i<unique_randoms.length; i++) {
			if (this.ad_holders[unique_randoms[i]] && this.ads[i]) {
				this.draw_ad(this.ad_holders[unique_randoms[i]], this.ads[i]);
			}
		}
		
		if (unique_randoms.length < this.ad_count) {
			for (var i=unique_randoms.length; i<this.ad_count; i++) {
				this.draw_ad(this.ad_holders[unique_randoms.length - 1], this.ads[i], true);
			}
		}
	},
	
	get_unique_randoms : function() {
		var maxRandom = this.ad_holders.length;
		var genRandom = 0;
		var randoms = new Array();
		
		do {
			if (randoms.length == this.ad_count) break;
			
			var rand = Math.round(Math.random() * maxRandom);
			
			var found = false;
			for (var i=0; i<randoms.length; i++) {
				if (randoms[i] == rand) {
					found = true;
					break;
				}
			}
			if (found == false) randoms[randoms.length] = rand;
		} while (randoms.length < maxRandom);
		return (randoms);
	},
	
	draw_ad : function(holder, ad, multiple) {
		holder.style.display = 'block';
		
		var the_html = '';
		if (multiple !== true) multiple = false;
		
		if (ad.type == 'script') {
			the_html = ad.script;
		} else {
			if (ad.width) holder.style.width = ad.width + 'px';
			if (ad.type == 'flash') {
				the_html = unescape('%3Cscript type="text/javascript"%3ENob2RunFoo("'+$d.image+'", '+ad.width+', '+ad.height+');%3C/script%3E');
			} else {
				var img = '%3Cimg src="'+ad.image+'" alt="'+ad.title+'" /%3E';
				the_html = unescape('%3Ca href="'+ad.link+'" title="'+ad.title+'"%3E'+img+'%3C/a%3E');
			}
		}
		
		if (multiple === true) {
			holder.innerHTML += unescape('%3Cdiv style="height:4px"%3E%3C/div%3E')+the_html;
		} else {
			holder.innerHTML = the_html;
		}
	}
};

var TFJAd = {
	parent : null,
	current : null,
	previous : null,
	wait : 4,
	slideTimer : null,
	now : null,
	
	init : function(thumbs) {
		var theLink = document.getElementById('tfjadlink');
		if (theLink) theLink.onclick = function() { jQuery.post(thumbs.rootdir+'includes/clickcount.php'); };
		
		thumbs = eval(thumbs);
		this.parent = document.getElementById('TFJThumbs');
		this.current = thumbs.current;
		this.previous = thumbs.previous;
		
		var slides = '<img src="'+this.current+'" alt="The Fashion Journal" id="TFJT_Curr" class="TFJThumb" />';
		slides += '<img src="'+this.previous+'" alt="The Fashion Journal" id="TFJT_Prev" class="TFJThumb" />';
		
		this.parent.innerHTML = slides;
		this.now = 'previous',
		document._TFJAd = this;
		
		this.fade();
		this.slideTimer = setInterval(this.fade, this.wait * 1000);
	},
	
	fade : function() {
		if (document._TFJAd.now == 'previous') {
			jQuery('#TFJT_Prev').fadeOut('normal');
			jQuery('#TFJT_Curr').fadeIn('normal');
			document._TFJAd.now = 'current';
		} else {
			jQuery('#TFJT_Curr').fadeOut('normal');
			jQuery('#TFJT_Prev').fadeIn('normal');
			document._TFJAd.now = 'previous';
		}
	}
};

var Nob2EventCalendar = {
	posturl : null,
	update : null,
	
	init : function (posturl, date) {
		this.posturl = posturl;
		this.show(date);
		this.update = document.getElementById('nob2-event-calendar-pan');
	},
	
	show : function (date) {
		date = date.split('/');
		if (isNaN(date[0]) || isNaN(date[0])) return (false);
		
		jQuery.post(this.posturl, { cmd : 'calendar', mm : date[1], yy : date[0] }, function(res) { Nob2EventCalendar.draw(res) }, 'json');
	},
	
	draw : function(res) {
		if (res.result == 'success') {
			this.update.innerHTML = res.data;
		}
	}
};