// JavaScript Document
window.addEvent('domready',function(){
	var today = new Date();
	var fifty = new Date();
	var Qs = [0,3,6,9];
	var thisQuarter = Math.floor( today.getMonth()/3 ) +1;
	var nQ = Qs[thisQuarter];
	var nextQstarts;
	if(thisQuarter==4) {
		nextQstarts= new Date(today.getFullYear() + 1, 0 ,1); 
	}else{
	nextQstarts= new Date(today.getFullYear(), nQ, 1);
	}
	var one_day=1000*60*60*24;
	var numtext=['zero','one','two','three','four','five','six','seven','eight','nine'];
	//Calculate difference btw the two dates, and convert to days
	var dd = Math.ceil((nextQstarts.getTime()-today.getTime())/(one_day));
	var ddf = (dd>10)?dd:'only&nbsp;' +numtext[dd];
	var pls = (dd==1)?'':'s';
	var dateDiff = ddf+"&nbsp;day"+pls+"&nbsp;left!";
	var fiftyOff1, fiftyURL1, fiftyURL2, fiftyIMG2, fiftyOff2;
	var promos=[];
	switch(thisQuarter){
	case 1:
	fiftyOff1 ='Save 50% on #3959 ' +dateDiff;
	fiftyURL1 = "https://www.ism.ws/KC/?Product_ID=655";
	//$('fifty1').set('html','<a href="https://www.ism.ws/KC/?Product_ID=655" target="_self"><img src="/KC/images/specials/50percentSpecial_1-to-3-2010.jpg" alt="Photo" width="400" height="400" hspace="0" vspace="0" border="0"/></a>');
	break;
	
	case 2:
	fiftyOffT = 'Beyond the Basics of Contract Writing';
	fiftyOff1 ='Save 50% on #3953 ' +dateDiff;
	fiftyURL1 = "https://www.ism.ws/KC/?Product_ID=650";
	fiftyIMG1 = '<img src="/KC/images/specials/50percentSpecial_3-to-6-2010.jpg" alt="Photo" width="400" height="400" hspace="0" vspace="0" border="0"/>';
	promos.push('Save 50% on <a href="'+fiftyURL1+'" target="_self">'+fiftyOffT+'</a> ' +dateDiff);
	break;
	
	case 3:
	fiftyOffT = 'The Negotiation Process';
	fiftyOff1 = 'Save 50% on #3955 ' +dateDiff;
	fiftyURL1 = 'https://www.ism.ws/KC/?Product_ID=652';
	fiftyIMG1 = '<img src="/KC/images/specials/50percentSpecial_7-to-9-2010.jpg" alt="Q3 special" width="400" height="400" hspace="0" vspace="0" border="0"/>';
	promos.push('Save 50% on <a href="'+fiftyURL1+'" target="_self">'+fiftyOffT+'</a> ' +dateDiff);
	break;
	
	case 4:
	fiftyOffT = 'Project Management for Supply Management Professionals';
	fiftyOff1 = 'Save 50% on #3966 ' +dateDiff;
	fiftyURL1 = 'https://www.ism.ws/KC/?Product_ID=5268';
	fiftyIMG1 = '<img src="/KC/images/specials/50percentSpecial_2_10-to-12-2010.jpg" alt="Q4 special 1" width="400" height="400" hspace="0" vspace="0" border="0"/>';
	promos.push('Save 50% on <a href="'+fiftyURL1+'" target="_self">'+fiftyOffT+'</a> ' +dateDiff);
	
	fiftyOffT2 = 'Price Analysis: Review';
	fiftyOff2 = 'Save 50% on #3958 ' +dateDiff;
	fiftyURL2 = 'https://www.ism.ws/KC/?Product_ID=654';
	fiftyIMG2 = '<img src="/KC/images/specials/50percentSpecial_1_10-to-12-2010.jpg" alt="Q4 special 2" width="400" height="400" hspace="0" vspace="0" border="0"/>';
	promos.push('Save 50% on <a href="'+fiftyURL2+'" target="_self">'+fiftyOffT2+'</a> ' +dateDiff);
	break;
	}
	//link + image for slide, label for slide
	var sli =[
			//  	['<a href="'+fiftyURL1+'" target="_self">'+fiftyIMG1+'</a>',fiftyOff1]
				
		//	,['<a href="'+fiftyURL2+'" target="_self">'+fiftyIMG2+'</a>',fiftyOff2]
			 ['<a href="https://www.ism.ws/KC/?Product_ID=11704" target="_self"><img src="/KC/images/specials/CPSDpromo.jpg" alt="Photo" width="400" height="400" hspace="0" vspace="0" border="0"/></a>',"New: CPSD&trade; Course"],
			 
			 ['<a href="http://www.ism-knowledgecenter.ws/KC/courses.cfm#cat_17?open=17" target="_self"><img src="/KC/images/specials/SSRpromo.jpg" alt="Photo" width="400" height="400" hspace="0" vspace="0" border="0"/></a>',"12 New SSR Courses!"]
			  
			  ,['<a href="https://www.ism.ws/KC/index.cfm?Product_ID=5568" target="_self"><img src="/KC/images/specials/3967.jpg" alt="Photo" width="400" height="400" hspace="0" vspace="0" border="0"/></a>',"New FREE ROB course"]
			  	  
			  ,['<a href="http://ism.ws/2237" target="_self"><img src="/KC/images/specials/3973csm.jpg" alt="Photo" width="400" height="400" hspace="0" vspace="0" border="0"/></a>',"New CPSM&reg; and CSM&trade; T3 Course"]
			  
			  ,['<a href="http://ism.ws/2179" target="_self"><img src="/KC/images/specials/3974.jpg" alt="Photo" width="400" height="400" hspace="0" vspace="0" border="0"/></a>',"New FREE Sustainability/Social Responsibility"]
			  
			  ];
			
	for (k=0; k<sli.length; k++){
		if(sli[k][1]!=undefined){
		$('box1').adopt(new Element('div',{'html':sli[k][0]}));
		var li = new Element('li',{'html':sli[k][1]});
		li.inject($('handles1'));
		}
		}
	//check if any INS courses still in the universe, if not remove ad & promotext
	/*var ins = new Date();
	ins.setFullYear(2010,3,7);
	if(today >= ins){
	var del = labels.splice(0,1);
	var del = hrefs.splice(0,1);
	$('promopromo').dispose();
	$('insTxt').dispose();
	}*/
			var waitInterval = 9000;
			
			var nS1 = new noobSlide({
				box: $('box1'),
				items: $$('#box1 div'),
				size: 400,
				handles: $$('#handles1 li'),
				onWalk: function(currentItem,currentHandle){
					this.handles.removeClass('active');
					currentHandle.addClass('active');
				}
				,autoPlay: true,
				interval: waitInterval,
				fxOptions: {
					duration: 1000,
					transition: Fx.Transitions.Expo.easeInOut,
					wait: false
				}
			});
	
	for (k=0; k<promos.length; k++){
		
			var sav = promos[k].split('%');
			var txt = '<span class="glaring">'+sav[0]+'%</span>'+sav[1];
		var p = new Element('p',{'html':txt});
		p.inject($('currentPromos'));
		
		}
		
	//add mousein/out behaviors for all slides
	/*
	$$('#box1 div').addEvents({
	
		'mouseover':function(){
		nS1.stop(); 
		},
	
		'mouseleave':function(){
		nS1.play(waitInterval,"next",false);
		}
	
	});
	*/
		});
