var Trident = {};
					
Trident.functions = {

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

	init: function () {
		this.postLinks();
		this.goForms();
		this.iconography();
	},
	
	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;					
					}
					
				}	
						
			}

		});		
		
	},
	
	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.');                
		                }		                						
					});
				}
			});
		}
		
		if($('#datasheetform')) {
			$('#datasheetform').validate({
				rules : {
					region		: "required",
					type		: "required",
					name		: "required",
					email		: "required email",
					remarks		: "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.');                
		                }		                						
					});
				}
			});
		}		
		
	},
	
	postLinks: function() {
	
		if($('#ico_navigation')) {
			var output = '';
			
			$('#ico_navigation').find('a').each(function() {
				var contents = $(this).html();
				var href = $(this).attr('href');
				
				$(this).toggleClass('post_link_ico');	
						
				if(contents == '%next_link%') {
					$(this).html('<img src="'+Trident.functions.themeDir+'/images/ico_back.gif" alt="Older entrie" />');
				} else {
					$(this).html('<img src="'+Trident.functions.themeDir+'/images/ico_next.gif" alt="Newer entrie" />');
				}
				Trident.functions.trace(href);
			});
		}
		
	},
	
	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);
			}
		}
	
	}

};