//author:marsn
//email:bugme@anderearbeitenlassen.de
//version:0.9.1 stable
//versioninfos: this is a real simple, first stable version of JSaal. it only contains some basic selectors and functions
//but it runs! feel free to use JSaal but please do not modify and redistribute the code! if you want to make JSaal better
//please do not touch the code by yourself but contact me on bugme@anderearbeitenlassen.de and i will try to integrate 
//your suggestions into the planning process of the next version.
//greetz, marsn

var get = {
//some basic selectors
	id: function(id) {
		return document.getElementById(id)
	},
	className: function(className){
		return document.getElementsByClassName(className)
	},
	name: function(name){
		return document.getElementsByName(name)
	},
	tag: function(tag){
		return document.getElementsByTagName(tag)
	},
	os: function(){
		aalDetection.init();
		return aalDetection.OS;
	},
	browser: function(){
		aalDetection.initIdentification();
		return aalDetection.browserNameShort;
	}
}

var go = {
	
//some basic methods/functions
	
	//focusses sreen, what else? ;)
	focus: function(id){
		get.id(id).focus()
	},
	
	//inserts css files after pageload
	insertCss: function(path){
		this.full30 = this.ie30Bug();
		if(!this.full30){
			var newStyleSheet = document.createElement('link'); 
			newStyleSheet.setAttribute('rel','stylesheet'); 
			newStyleSheet.setAttribute('href',path); 
			this.byTag('head')[0].appendChild(newStyleSheet);
		};
	},
	
	ie30Bug: function(){
			if((this.byTag('style').length + this.byTag('link').length) > 30){
				alert('You reached the magic 30 man, cut down your CSS code.');
				return true;
			}
	},
	
	//creates some kind of "random" number, integer
	random: function(){
		var date = new Date();
		var rand = Math.random();
		var randomNum;
		date = date.getTime();
		rand = Math.floor(rand * date);
		date = new Date();
		date = Math.floor(date.getMilliseconds() / date.getMonth());
		randomNum = parseInt(Math.floor( (rand * 187) + date ));
		//
		return randomNum;
	}
	
}

//aalDetection
//the aalDetection bascially has to be called via get.os or get.browser. BUT you can get more detailed results by calling the function itself. Description follows...
var aalDetection = {
	
	initIdentification: function(){
	this.browserName = this.identifyBrowser(this.browserData, 'full') || 'unkown';
	this.browserNameShort = this.identifyBrowser(this.browserData, 'short') || 'unkown';
	this.browserEngine = this.identifyBrowser(this.browserData, 'engine') || 'unknown';
	this.browserVersion = this.identifyVersion(this.browserData) || 'unknown';
	this.isIE = this.browserNameShort == 'msie';
	},
	identifyVersion: function(data){
		context = navigator.userAgent.toLowerCase();
		if(this.browserNameShort == 'msie'){
			context = context.split(this.browserNameShort + " ")[1];
			context = context.split(";")[0];
			return context;
		}
		else {
			context = context.split(this.browserNameShort + "/")[1];
			context = context.split(" ")[0];
			return context;
		}
	},
	identifyBrowser: function(data, type){
		this.actData = navigator.userAgent.toLowerCase();
		
		for(i=0; i<data.length; i++){
			if(this.actData.indexOf(data[i].keyword) != -1){
				switch(type){
					case 'full': return data[i].actBrowser;
					break;
					
					case 'short': return data[i].shortDesc;
					break;
					
					case 'engine': return data[i].engine;
					break;
					
					default: return data[i].actBrowser;
				}
			}
		}
		
	},
	browserData: [
	{
		keyword: 'msie',
		actBrowser: 'Microsoft Internet Explorer',
		shortDesc: 'msie',
		engine: 'trident'
	},
	{
		keyword: 'safari',
		actBrowser: 'Safari',
		shortDesc: 'safari',
		engine: 'webkit'
	},
	{
		keyword: 'firefox',
		actBrowser: 'Mozilla Firefox',
		shortDesc: 'firefox',
		engine: 'gecko'
	},
	{
		keyword: 'opera',
		actBrowser: 'Opera',
		shortDesc: 'opera',
		engine: 'presto'
	},
	{
		keyword: 'konqueror',
		actBrowser: 'Konqueror',
		shortDesc: 'konqueror',
		engine: 'webkit'
	},
	{
		keyword: 'omniweb',
		actBrowser: 'OmniWeb',
		shortDesc: 'omniweb',
		engine: 'webkit'
	},
	{
		keyword: 'chrome',
		actBrowser: 'Google Chrome',
		shortDesc: 'chrome',
		engine: 'webkit'
	},
	{
		keyword: 'galeon',
		actBrowser: 'Galeon',
		shortDesc: 'galeon',
		engine: 'gecko'
	},
	{
		keyword: 'epiphany',
		actBrowser: 'Epiphany',
		shortDesc: 'epiphany',
		engine: 'webkit'
	},
	{
		keyword: 'camino',
		actBrowser: 'Camino',
		shortDesc: 'camino',
		engine: 'gecko'
	},
	{
		keyword: 'seamonkey',
		actBrowser: 'SeaMonkey',
		shortDesc: 'seamonkey',
		engine: 'gecko'
	},
	{
		keyword: 'lynx',
		actBrowser: 'Lynx',
		shortDesc: 'lynx',
		engine: 'own'
	},
	{
		keyword: 'amaya',
		actBrowser: 'amaya',
		shortDesc: 'amaya',
		engine: 'own'
	},
	{
		keyword: 'icab',
		actBrowser: 'iCab',
		shortDesc: 'icab',
		engine: 'webkit'
	}
	],
		
	init: function(){
		this.OS = this.detectOS(this.aalOS) || "Unknown Operating System detected.";
		
	},
	
	detectOS: function(data){
		this.actData = navigator.platform.toLowerCase();
		for(i=0; i < data.length; i++){
			if(this.actData.indexOf(data[i].searchString) != -1){
				return data[i].actOS;
			}
		}
	},
	
	aalOS: [
	{
		searchString: 'win',
		actOS: 'Windows'
	},
	{
		searchString: 'mac',
		actOS: 'Mac OS'
	},
	{
		searchString: 'iphone',
		actOS: 'iPhone/iPod'
	},
	{
		searchString: 'linux',
		actOS: 'Linux'
	}
	]
}

var fx = {
	hide: function(id){
		get.id(id).style.display = "none";
	},
	show: function(id){
		get.id(id).style.display = "block";
	},
	tabInit: function(def, actTab){
		this.tabShow(def, actTab);
	},
	tabShow: function(id, actTab){
		this.act;
		this.last;
		this.actTab;
		this.lastTab;
		
		if(this.act){
			this.last = this.act;
		}
		if(this.actTab){
			this.lastTab = this.actTab;
		}
		
		this.act = id;
		if(actTab){
			this.actTab = actTab;
		}
		
		if(this.last){
			this.hide(this.last);
		}
		if(this.lastTab){
			get.id(this.lastTab).className = 'inactive';
		}
		this.show(this.act);
		if(this.actTab){
			get.id(this.actTab).className = 'active';
		}
	}
	
}

