/* App model */
		var slideshow = {
			auto: false,
			inital: true,
			curslide: 0,
			curpos: 0,
			sCount: 0,
			count: 0,
			unique_id: 0,
			direction: 1,
			curtimeout: 0,
			activeInterval: null,
			activeTimeout: null,
			slideshow: {},
			page: {
				base_uri: '',
				slideshow: ''
			},
			slides: [],
			setup: function () {
				var qid = this.unique_id;
				$('#autoplay_'+qid).bind('click', {slideshow: this},function (obj) {
					obj.preventDefault();
					obj.data.slideshow.autoplay(this);
					return false;
				});
				
				$('#slide_total_'+qid).html(this.sCount);
				$('#prev_button_'+qid).bind('click', {slideshow: this},function (obj) { 
					obj.preventDefault();
					obj.data.slideshow.previous();
					return false;
				});
				$('#next_button_'+qid).bind('click', {slideshow: this},function (obj) { 
					obj.preventDefault();
					obj.data.slideshow.next(); 
					return false;
				});
				this.load();
			},
			autoplay: function (obj)
			{
				if (obj.innerHTML == 'AUTOPLAY')
				{
					obj.innerHTML = 'PAUSE';
					this.resume();
				}
				else if (obj.innerHTML == 'PAUSE')
				{
					obj.innerHTML = 'RESUME';
					this.pause();
				}
				else
				{
					obj.innerHTML = 'PAUSE';
					this.resume();
				}
			},
			resume: function() {
				this.auto = true;
				this.load();
			},
			pause: function () {
				this.auto = false;
				clearTimeout(this.activeTimeout);
			},
			load: function () {
				this.curpos += this.direction;
				if (this.curpos < 0 || this.curpos == this.count) //wrap?
				{
					if (this.curpos < 0)
					{
						this.curpos = this.count - 1;
						this.curslide = this.count;
					}
					else
					{
						this.curpos = 0;
						this.curslide = 1;
					}
				}
				
				if (this.slides[this.curpos].tree_type == 'slide')
				{
					//document.title = 'Who What Wear | '+ this.slideshow.slideshow_title.replace(/(<([^>]+)>)/ig,"") + ' | ' + this.slides[this.curpos].slide_title.replace(/(<([^>]+)>)/ig,"");
					this.curslide = this.slides[this.curpos].slide_num;
					if (this.auto)
					{
						clearTimeout(this.activeTimeout);
						this.curtimeout = this.slides[this.curpos].slide_timeout;
						this.direction = 1;
						var mslideshow = this;
 						this.activeTimeout = setTimeout(function () { mslideshow.load() }, this.curtimeout * 1000)
					}
					
					$('#cur_slide_'+this.unique_id).html(this.curslide);
					$('#slide_title_'+this.unique_id).html(this.slides[this.curpos].slide_title);
					$('#slide_desc_'+this.unique_id).html(this.slides[this.curpos].slide_promo);
					var tmpcontent = '';
					if(this.slides[this.curpos].slide_url != '' && this.slides[this.curpos].slide_url != null)
					{
						tmpcontent = '<a href="'+this.slides[this.curpos].slide_url+'" target="'+this.slides[this.curpos].slide_target+'">';
					}
					tmpcontent += '<img src="'+this.slides[this.curpos].slide_image+'" />';
					if(this.slides[this.curpos].slide_url != '' && this.slides[this.curpos].slide_url != null) 
					{
						tmpcontent += '</a>';
					}
					
					$('#main_content_'+this.unique_id).html(tmpcontent);
					if (this.slides[this.curpos].slide_pixel != '')
					{
						tmpcontent = '<img src="'+this.slides[this.curpos].slide_pixel+'" width="1" height="1" />';
						$('#pixel_cont_'+this.unique_id).html(tmpcontent);
					}
					//is slide
					$('#fblike_'+this.unique_id).html('<iframe src="http://www.facebook.com/plugins/like.php?href='+encodeURIComponent(this.page.base_uri+''+this.page.slideshow+ '/' + this.slides[this.curpos].slide_link)+'/&amp;layout=button_count&amp;show_faces=false&amp;width=108&amp;action=like&amp;locale=en_EN&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:78px; height:30px;background-color: transparent;" allowtransparency="true"></iframe>');
					tweetmeme_source = 'WhoWhatWear';
					tweetmeme_url = this.page.base_uri+''+this.page.slideshow + '/' + this.slides[this.curpos].slide_link + '/';
					tweetmeme_style = 'compact';
					if (!this.inital)
					{   
					    // tracks individual slides on slide change
                        $tracUrl = '/website/slideshow-story/'+this.page.slideshow + '/' + this.slides[this.curpos].slide_link + '/';
						pageTracker._trackPageview($tracUrl);
						//alert($tracUrl);
					}
					this.inital = false;
					$('#twlike_'+this.unique_id).html(this.getTweetMeme());
				}
				else
				{
					if (undefined !== adslideshow)
					{
						this.next();
						return;
					}
					adslideshow = this;
					if (this.auto)
					{
						clearTimeout(this.activeTimeout);
						clearInterval(this.activeInterval);
					}
					//is ad
					$('#main_content_'+this.unique_id).html('&nbsp;');
					var tmpcontent = '';
					if (this.slides[this.curpos].ad_url != '')
					{
						tmpcontent = '<a href="'+this.slides[this.curpos].ad_url+'" target="'+this.slides[this.curpos].ad_target+'">';
					}
					tmpcontent += '<img src="'+this.slides[this.curpos].ad_image+'" style="width:'+this.slides[this.curpos].ad_width+'px;height: '+this.slides[this.curpos].ad_height+'px;" />';
					if (this.slides[this.curpos].ad_url != '')
					{
						tmpcontent += '</a>';
					}
					this.curtimeout = this.slides[this.curpos].ad_timeout;
					$.fancybox({centerOnScroll:true, modal: true, padding: 0, content: tmpcontent, title: 'SLIDESHOW WILL CONTINUE IN <span id="ad_timeout">'+this.curtimeout+'</span> SECONDS<br/><strong><a id="close_ad" style=" color:#fff !important; font-weight:bold; display:block; text-align:center;"; href="#">SKIP THIS AD</a></strong>',
								onComplete: function () {
												$('#close_ad').click(function (ev) {
													ev.preventDefault();
													$.fancybox.close();
													clearInterval(adslideshow.activeInterval);
													var tmpslideshow = adslideshow;
													adslideshow = undefined;
													tmpslideshow.load();
													return false;
												});
												adslideshow.activeInterval = setInterval(function () {
													if (adslideshow.curtimeout != 0)
													{
														adslideshow.curtimeout--;
														$('#ad_timeout').html(adslideshow.curtimeout);
													}
													else
													{
														$('#close_ad').click();
													}
												}, 1000);
											}});
				
					if (this.slides[this.curpos].ad_pixel != '')
					{
						tmpcontent = '<img src="'+this.slides[this.curpos].ad_pixel+'" width="1" height="1" />';
						$('#pixel_cont_'+this.unique_id).html(tmpcontent);
					}					
				}
				
			},
			next: function () {
				this.direction = 1;
				this.load();
				return false;
			},
			previous: function () {
				this.direction = -1;
				this.load();
				return false;
			},
			getTweetMeme: function()
			{
				var _url=window.location.href;
				var _url=_url.replace(/((?:\?|&)?fbc_receiver=.+)?(?:#.*)?$/,"");
				var url=escape((typeof tweetmeme_url=="string")?tweetmeme_url:((typeof TWEETMEME_URL=="string")?TWEETMEME_URL:_url)).replace(/\+/g,"%2b");
				var source=(typeof tweetmeme_source=="string")?escape(tweetmeme_source):((typeof TWEETMEME_SOURCE=="string")?escape(TWEETMEME_SOURCE):false);
				var style=(typeof tweetmeme_style=="string")?escape(tweetmeme_style):((typeof TWEETMEME_STYLE=="string")?escape(TWEETMEME_STYLE):"normal");
				var service=(typeof tweetmeme_service=="string")?escape(tweetmeme_service):((typeof TWEETMEME_SERVICE=="string")?escape(TWEETMEME_SERVICE):false);
				var service_api=(typeof tweetmeme_service_api=="string")?escape(tweetmeme_service_api):((typeof TWEETMEME_SERVICE_API=="string")?escape(TWEETMEME_SERVICE_API):false);
				var alias=(typeof tweetmeme_alias=="string")?escape(tweetmeme_alias):((typeof TWEETMEME_ALIAS=="string")?escape(TWEETMEME_ALIAS):false);
				var hashtags=(typeof tweetmeme_hashtags=="string")?escape(tweetmeme_hashtags):((typeof TWEETMEME_HASHTAGS=="string")?escape(TWEETMEME_HASHTAGS):false);
				var space=(typeof tweetmeme_space=="number")?escape(tweetmeme_space):((typeof TWEETMEME_SPACE=="number")?escape(TWEETMEME_SPACE):false);
				var width=(typeof tweetmeme_width=="number")?escape(tweetmeme_width):((typeof TWEETMEME_WIDTH=="number")?escape(TWEETMEME_WIDTH):false);
				var src="http://api.tweetmeme.com/button.js";
				switch(style){case"compact":var h=20;
				var w=90;
				break;
				default:var h=61;
				var w=50;
				break}if(width){w=width}src+="?url="+url;
				src+="&style="+style;
				if(source!=false){src+="&source="+source}if(service){src+="&service="+service}if(service_api){src+="&service_api="+service_api}if(alias){src+="&alias="+alias}if(hashtags){src+="&hashtags="+hashtags}if(space){src+="&space="+space}if(document&&document.referrer){var ref=document.referrer;
				if(ref){src+="&o="+escape(ref)}}src+="&b=1";
				tweetmeme_url=null;
				TWEETMEME_URL=null;
				tweetmeme_source=null;
				TWEETMEME_SOURCE=null;
				tweetmeme_service=null;
				TWEETMEME_SERVICE=null;
				tweetmeme_service_api=null;
				TWEETMEME_SERVICE_API=null;
				tweetmeme_style=null;
				TWEETMEME_STYLE=null;
				tweetmeme_alias=null;
				TWEETMEME_ALIAS=null;
				tweetmeme_hashtags=null;
				TWEETMEME_HASHTAGS=null;
				tweetmeme_space=null;
				TWEETMEME_SPACE=null;
				return '<iframe src="'+src+'" height="'+h+'" width="'+w+'" frameborder="0" scrolling="no" allowtransparency="true"></iframe>';
			}
		};
/* end app model */
