// Jesse Thomson
// Last Modified: 04 15 08

// Globals
	var sections;
	var urls;
		
	var opacityFx; // for media div
	var contentFx; // for content div
	var livechatter; // for livechat button
	
	var currentIndex = 0;
	var previousIndex = 5;
	var nextIndex = 0;

var Site = {
	topnav: function(){
		Elements.addEvents($$('div#tnarrows img'), {
			'mouseenter': function(){
				this.tween('background-color','#546c93');
			},
			'mouseleave': function(){
				this.tween('background-color', '#1b3b78');
			}
		});
		
		Elements.addEvents($$('div#tnbotrow img'), {
			'mouseenter': function(){
				this.tween('background-color', '#546c93');
			},
			'mouseleave': function(){
				this.tween('background-color', '#97a6bf');
			}
		});
	}
}

var Has = {
	services: function( whichServices ) {
		whichServices.each(function(myZero, myZeroIndex, myArray){
			myZero.addEvent('click', function(){
				new Request.HTML({
					url: 'media/services.html',
					onRequest: function(){
						opacityFx.start(0);
						contentFx.start(745);
						livechatter.start(0);
					},
					onFailure: function(){},
					onComplete: function(responseTree, responseElements, responseHTML, responseJavascript){
						(function(){$('media').set('html', responseHTML)}).delay(750);
						(function(){opacityFx.start(1)}).delay(1250);
					}
				}).get();
			});
		});
	},
	
	faqs: function( whichFaqs ) {
		whichFaqs.each(function(myFaq, myFaqIndex, myArray){
			myFaq.addEvent('click', function(){
				new Request.HTML({
					url: 'media/faq.html',
					onRequest: function(){
						opacityFx.start(0);
						contentFx.start(800);
						livechatter.start(0);
					},
					onFailure: function(){ alert('Wait, what?! Something went wrong, how did you do that?') },
					onComplete: function(responseTree, responseElements, responseHTML, responseJavascript){
						(function(){$('media').set('html', responseHTML)}).delay(750);
						(function(){opacityFx.start(1)}).delay(1250);
					}
				}).get();
			});
		});
	},
	
	backs: function( whichbacks ) {
		whichbacks.each(function(myBack, myBackIndex, myBackArray){
			myBack.addEvent('click', function(){
				new Request.HTML({
					url: 'media/feedback2.html',
					onRequest: function(){
						opacityFx.start(0);
						contentFx.start(840);
						livechatter.start(0);
					},
					onFailure: function(){ alert('Wait, what?! Something went wrong, how did you do that?') },
					onComplete: function(responseTree, responseElements, responseHTML, responseJavascript){
						(function(){$('media').set('html', responseHTML)}).delay(750);
						(function(){opacityFx.start(1)}).delay(1250);
					}
				}).get();
			});
		});
	},
	
	infoboxes: function( whichBoxes ) {
		whichBoxes.each(function(myElement, myIndex, myArray){
			myElement.addEvent('click', function(){				
				new Request.HTML({
					url: 'media/' + urls[myIndex] + '.html',
					onRequest: function(){
						opacityFx.start(0);
						contentFx.start(745);
						livechatter.start(1);
						currentIndex = myIndex;
						if (currentIndex == 0) {
							nextIndex = 1;
							previousIndex = 5;
						} else if (currentIndex == 5) {
							nextIndex = 0;
							previousIndex = 4;
						} else {
							nextIndex = currentIndex + 1;
							previousIndex = currentIndex -1;
						}
					},
					onFailure: function(){ alert('Wait, what?! Something went wrong, how did you do that?') },
					onComplete: function(responseTree, responseElements, responseHTML, responseJavascript){
						(function(){$('media').set('html', responseHTML)}).delay(750);
						(function(){opacityFx.start(1)}).delay(1250);						
					}
				}).get();
			});
		});
	},
	
	footerboxes: function( whichBoxes ) {
		whichBoxes.each(function(myElement, myIndex, myArray){
			myElement.addEvent('click', function(){				
				new Request.HTML({
					url: 'media/' + urls[myIndex] + '.html',
					onRequest: function(){
						opacityFx.start(0);
						contentFx.start(745);
						livechatter.start(1);
						currentIndex = myIndex;
						if (currentIndex == 0) {
							nextIndex = 1;
							previousIndex = 5;
						} else if (currentIndex == 5) {
							nextIndex = 0;
							previousIndex = 4;
						} else {
							nextIndex = currentIndex + 1;
							previousIndex = currentIndex -1;
						}
					},
					onFailure: function(){ alert('Wait, what?! Something went wrong, how did you do that?') },
					onComplete: function(responseTree, responseElements, responseHTML, responseJavascript){
						(function(){$('media').set('html', responseHTML)}).delay(750);
						(function(){opacityFx.start(1)}).delay(1250);						
					}
				}).get();
			});
		});
	}
}

var Requests = {
 	
	set: function(){
		sections = [$('one'), $('two'), $('thr'), $('fou'), $('fiv'), $('six')];
		urls = ['hdtvhometheater', 'computer', 'mobile', 'education', 'creative', 'professional'];
		
		opacityFx = new Fx.Tween('media', 'opacity');
		contentFx = new Fx.Tween('content', 'height');
		livechatter = new Fx.Tween('livechat', 'opacity');
	if ($('rich')) {	
		sections.each(function(myElement, myIndex, myArray){
			myElement.addEvent('click', function(){				
				new Request.HTML({
					url: 'media/' + urls[myIndex] + '.html',
					onRequest: function(){
						opacityFx.start(0);
						contentFx.start(745);
						livechatter.start(1);
						currentIndex = myIndex;
						if (currentIndex == 0) {
							nextIndex = 1;
							previousIndex = 5;
						} else if (currentIndex == 5) {
							nextIndex = 0;
							previousIndex = 4;
						} else {
							nextIndex = currentIndex + 1;
							previousIndex = currentIndex -1;
						}
					},
					onFailure: function(){ alert('Wait, what?! Something went wrong, how did you do that?') },
					onComplete: function(responseTree, responseElements, responseHTML, responseJavascript){
						(function(){$('media').set('html', responseHTML)}).delay(750);
						(function(){opacityFx.start(1)}).delay(1250);						
					}
				}).get();
			});
		});
		
		$('autoprevious').addEvent('click', function(){
			sections[previousIndex].fireEvent('click');
		});
		
		$('autonext').addEvent('click', function(){
			sections[nextIndex].fireEvent('click');
		});
	}	
		if ($('rich')) {
			Has.services([$('zero'), $('ibzero'), $('pzero'), $('fzero')]);
			Has.faqs([$('faq'), $('ibfaq'), $('ffaq'), $('fzero')]);
			Has.backs([$('fback'), $('ibfback')]);
			Has.infoboxes([$('ibone'), $('ibtwo'), $('ibthr'), $('ibfou'), $('ibfiv'), $('ibsix')]);
			Has.footerboxes([$('fone'), $('ftwo'), $('fthr'), $('ffou'), $('ffiv'), $('fsix')]);
		}


		var richOpacityFx = new Fx.Tween('rich', 'opacity');
		
		$('requestliveview').addEvent('click', function(){
			new Request.HTML({
				url: 'special/liveview.html',
				onRequest: function(){
					richOpacityFx.start(0);
				},
				onFailure: function(){ alert('Wait, what?! Something went wrong, how did you do that?') },
				onComplete: function(responseTree, responseElements, responseHTML, responseJavascript){
					(function(){$('rich').set('html', responseHTML)}).delay(750);
					(function(){richOpacityFx.start(1)}).delay(1250);
				}
			}).get();
		});
		
		if ($('whichmedia')) {
			var amedias = [$('amediaplayer'), $('amediaactivex'), $('amediajava')];
			amedias.each(function(myElement, myIndex, myArray){
				myElement.addEvents({
					'mouseenter': function(){
						myElement.getFirst('img').set('src', 'http://www.smartsquad.com/images/media/liveview/checkedbox.png');
					},
					'mouseleave': function(){
						myElement.getFirst('img').set('src', 'http://www.smartsquad.com/images/media/liveview/emptycheckbox.png');
					}
				});
			});
		}
		
		
	}
}

var Video = {
	sample: function() {
	
		var myRequest = new Request.HTML({
			url: 'video/intro032608.html',
			onRequest: function(){},
			onFailure: function(){ alert('Wait, what?! Something went wrong, how did you do that?') },
			onComplete: function(rTree, rElems, rHTML, rJavascript){
				$('richpicture').set('html', rHTML);
			}
		}).get();	
	}
	
}

window.addEvents({
	'domready': function() {
		Site.topnav();
	},
	
	'load': function(){
		Requests.set();
		
		if ($('rich')) {
			Video.sample();
		}	
	}
	
});