var Trident = {};
					
Trident.functions = {

	themeDir: 'this variable is automatically set by wordpress in the document.ready function...',
	flashContent: 'flash/index2.swf',
	homeNewsIndex: null,
	homeNewsTotal: null,

	init: function () {
		this.postLinks();
		this.goForms();
		this.iconography();
		//this.USAdataInit();
		this.initHomeNews();
	},
	
	iconography: function() {
		
		$('a').each(function() {
			var contents = $(this).attr('href');
			
			if (contents != undefined) {
							
				var contentsArray = contents.split('.');
				if (contentsArray instanceof Array) {
				
					var amount = contentsArray.length;
					var contentsExt = contentsArray[amount-1];
					
					switch (contentsExt) {
						case 'pdf':
							$(this).toggleClass('ico_pdf');
						break;
						case 'doc':
							$(this).toggleClass('ico_doc');
						break;
						case 'zip':
							$(this).toggleClass('ico_zip');
						break;					
					}
					
				}	
						
			}

		});		
		
	},
	
	initHomeNews: function() {
		$('.home-post:first').addClass('active');
		this.homeNewsIndex = 1;
		this.homeNewsTotal = $('.home-post').size();
		$('#ico_navigation .next').hide();
	},
	
	goForms: function() {
		if($('#contactform')) {
			$('#contactform').validate({
				rules : {
					name		: "required",
					email		: "required email",
					question	: "required"
				},
				submitHandler: function(form) {
					$(form).ajaxSubmit({
		                url		: Trident.functions.themeDir + '/scripts/formhandler.php',
		                type	: 'post',
		                success	: function() {
							$('.form').html('Your question has been submitted succesfully.');                
		                }		                						
					});
				}
			});
		}
		
		/*
			2010-09-24 - JHS: Fixed and enhanced this
		*/
		if($('#datasheetform')) {
			$('#datasheetform').validate({
				rules : {
					type		: "required",
					name		: "required",
					title		: "required",
					company		: "required",
					email		: "required email",
					region		: "required",
					relation	: "required",
					nda			: "required"
				},
				submitHandler: function(form) {
					$(form).ajaxSubmit({
		                url		: Trident.functions.themeDir + '/scripts/formhandler.php',
		                type	: 'post',
		                success	: function() {
							$('.form').html('Your request has been submitted succesfully.');                
		                }		                						
					});
				}
			});
			
			$('#datasheetform #region').change(function() {
				if($('#datasheetform #region').val()=='US'){
					$('#datasheetform #state').removeAttr("disabled"); 
					$('#datasheetform #city').removeAttr("disabled"); 
					$('#datasheetform #state').rules('add',{required: true});
					$('#datasheetform #city').rules('add',{required: true});
					$('#datasheetform #statelabel').html('State: *');
					$('#datasheetform #citylabel').html('City: *');
				} else {
					$('#datasheetform #state :selected').removeAttr("selected"); 
					$('#datasheetform #state').attr("disabled", true);
					$('#datasheetform #city').attr("disabled", true); 
					$('#datasheetform #city').val(""); 
					$('#datasheetform #state').rules('remove');
					$('#datasheetform #city').rules('remove');
					$('#datasheetform #statelabel').html('State:');
					$('#datasheetform #citylabel').html('City:');
				}
			});

			
		}		
		
	},	
	
	postLinks: function() {
		$('#ico_navigation .prev').bind('click', Trident.functions.prevNewsItem);
		$('#ico_navigation .next').bind('click', Trident.functions.nextNewsItem);
	},
	
	prevNewsItem: function() {
		$('#news_ticker .active').removeClass('active');		
		
		Trident.functions.homeNewsIndex = Trident.functions.homeNewsIndex + 1;
		$('#ico_navigation .next').show();

		var loopIndex = 0
		$('.home-post').each(function() {
			loopIndex++;
			if(loopIndex==Trident.functions.homeNewsIndex) {
				$(this).addClass('active');
			}
		});
		
		if(Trident.functions.homeNewsIndex == Trident.functions.homeNewsTotal) {
			$('#ico_navigation .prev').hide();
		}
		
		return false;
	},

	nextNewsItem: function() {
		$('#news_ticker .active').removeClass('active');	
		
		Trident.functions.homeNewsIndex = Trident.functions.homeNewsIndex - 1;
		$('#ico_navigation .prev').show();

		var loopIndex = 0
		$('.home-post').each(function() {
			loopIndex++;
			if(loopIndex==Trident.functions.homeNewsIndex) {
				$(this).addClass('active');
			}
		});
		
		if(Trident.functions.homeNewsIndex < 2 ) {
			$('#ico_navigation .next').hide();
		}		
		
		return false;
	},
	
	homeFlash: function() {
		var userHasFlash = $.flash.available;
		
		//userHasFlash = false;
		if(userHasFlash) {
		
			var pWidth = $('#home_animation').width();
			var pHeight = $('#home_animation').height();
			
			$('#home_animation').flash({
				swf: this.themeDir+'/'+this.flashContent,
				height: pHeight,
				width: pWidth				
			});		
			
		} else {
		
			$('#home_animation').addClass('noflash');
			
		}
		
	},
	
	trace: function (trace){
		if(typeof console =='object') {
			if(typeof trace =='string' || typeof console.dir !='function'){
				console.info("Trace: "+trace);
			}else{
				console.dir(trace);
			}
		}
	
	}

};
