window.onload = function(e){
	alertDisplay.init();
}
alertDisplay = {
	init: function() {
		if(!document.getElementById || !document.getElementById ('alertResolution')){
			return;
		}
	 	if (screen.width>=640 && screen.width<1024 && !readCookie('nscures')){
			//set the cookie
			createCookie('nscures','1');
			//fade in the message
			alertID = 'alertResolution';
			theAlert = document.getElementById (alertID);
			this.setOpacity(theAlert, 0);
			theAlert.style.visibility = 'visible';
			window.setTimeout("alertDisplay.fadeIn('"+alertID+"',"+0+")", 1000);
		}
	},
	setOpacity: function(obj, opacity) {
		opacity = (opacity == 100)?99.999:opacity;
		// IE/Win
		obj.style.filter = "alpha(opacity:"+opacity+")";
		// Safari<1.2, Konqueror
		obj.style.KHTMLOpacity = opacity/100;	  
		// Older Mozilla and Firefox
		obj.style.MozOpacity = opacity/100;	  
		// Safari 1.2, newer Firefox and Mozilla, CSS3
		obj.style.opacity = opacity/100;
	},
	fadeIn: function(objId,opacity) {
		if (document.getElementById) {
			obj = document.getElementById(objId);
			if (opacity <= 100) {
				this.setOpacity(obj, opacity);
				opacity += 5;
				window.setTimeout("alertDisplay.fadeIn('"+objId+"',"+opacity+")", 100);
			}else{
				window.setTimeout("alertDisplay.fadeOut('"+objId+"',"+opacity+")", 20000);
			}
		}
	},
	fadeOut: function(objId,opacity) {
		if (document.getElementById) {
			obj = document.getElementById(objId);
			if (opacity >= 0) {
				this.setOpacity(obj, opacity);
				opacity -= 5;
				window.setTimeout("alertDisplay.fadeOut('"+objId+"',"+opacity+")", 100);
			}
		}
	}
}
/*cookie functions used in alert resolution*/
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
function eraseCookie(name) {
	createCookie(name,"",-1);
}

if (typeof jQuery !== "undefined") {
	
(function($){
	$.extend({

		options: {},
		slideshowPages: [],
		autoPlayInterval: null,

		// our constructor. This creates and (if required) starts auto-playing the slideshow
		slideshow: function(opts){
		var options = {
				slideshowElement: "promoShow",			// the name of the wrapper slideshow elements
				slideshowPageClass: "promoItem",		// the class name of the pages
				slideshowNavClass: "promoPagination",	// the class applied to the (generated) nav element 
				slideshowNavItemPrefix: "item",			// the class applied to all nav items 
				slideshowNavItemSelected: "current",	// the nav item class identifying the current page
				slideshowPlayBtnClass: "control",		// the class of the play button
				slideshowPlayBtnActiveClass: "play",	// the class of the play button when auto-playing
				autoPlay: true,							// whether or not it should auto-play on instantiation
				currentPage: 1,							// the current selected page
				fadeSpeed: 800,							// the speed at which the pages fade in and out 
				pageDuration: 3000						// how long each page should appear
			};
			jQuery.extend(options, opts);
			this.options = options;

			// locate the pages in the slideshow and stash them in slideshowPages
			this.slideshowPages = $("." + options.slideshowPageClass);

			// create and insert the slideshow nav 
			this.createNav();

			// if requested, start auto-play
			if (options.autoPlay)
			this.startAutoPlay();
		},

		// called on initialization; this creates and embeds the navigation into the DOM 
		createNav: function(){
			var navLi = $("<li></li>");
			var nav = $("<ul></ul>");
			navLi.attr("class", this.options.slideshowNavClass);

			var currSlideshow = this;
			var playBtn = $("<li></li>");
			playBtn.text("pause");
			playBtn.addClass(this.options.slideshowPlayBtnClass);

			if (this.options.autoPlay)
			    playBtn.addClass(this.options.slideshowPlayBtnActiveClass);

			playBtn.bind("click", function(e) { currSlideshow.toggleAutoPlay(e); });
			nav.append(playBtn);
			
			// add the nav items
			for (var i=1; i<=this.slideshowPages.length; i++){
			var item = $("<li></li>");
			item.addClass(this.options.slideshowNavItemPrefix + i);
				if (this.options.currentPage == i)
					item.addClass(this.options.slideshowNavItemSelected);

				item.bind("click", {page: i},  function(e) { e.data.isFromUser = true; currSlideshow.showPage(e); });
				item.text(i);
				nav.append(item);
			};

			// insert the nav into the page
			navLi.append(nav);
			$("." + this.options.slideshowElement).prepend(navLi);
		},
		// Shows an actual page, hiding the last one
		showPage: function(e){
			var page = e.data.page; 
			var opts = this.options;
			if (page == opts.currentPage)
				return;
			
			this.stopAutoPlay();
			this._updateNavClasses(opts, opts.currentPage, page);
			this.options.currentPage = page;
		},
		// called by the auto-play mechanism only
		showNextPage: function(){
			var opts = this.options;
			var currPage = opts.currentPage;
			var nextPage = (currPage % this.slideshowPages.length) + 1;
			this._updateNavClasses(opts, currPage, nextPage);
			this.options.currentPage = nextPage;
		},
		startAutoPlay: function(){
			$("." + this.options.slideshowNavClass + " li:first").removeClass(this.options.slideshowPlayBtnActiveClass);
			this.options.autoPlay = true;
			var currSlideshow = this;
			this.options.autoPlayInterval = setInterval(function() { currSlideshow.showNextPage(); }, this.options.pageDuration);
		},
		stopAutoPlay: function(){
			$("." + this.options.slideshowNavClass + " li:first").addClass(this.options.slideshowPlayBtnActiveClass);
			window.clearInterval(this.options.autoPlayInterval);
			this.options.autoPlay = false;
		},
		toggleAutoPlay: function(){
			if (this.options.autoPlay)
			{
				this.stopAutoPlay();
			} else {
				// we *immediately* move to the next page. If we wait, it looks like clicking the button did nothing
				this.showNextPage();
				this.startAutoPlay();
			}
		},
		_updateNavClasses: function(opts, from, to){
			$("." + opts.slideshowPageClass + from).fadeOut(opts.fadeSpeed);
			$("." + opts.slideshowNavItemPrefix + from).removeClass(opts.slideshowNavItemSelected);
			$("." + opts.slideshowPageClass + to).fadeIn(opts.fadeSpeed);
			$("." + opts.slideshowNavItemPrefix + to).addClass(opts.slideshowNavItemSelected);
		}
	});
})(jQuery);

	jQuery(function(){
		jQuery.slideshow({pageDuration: 6000});
	});
}
