var page = ($pick(window.location.hash,'#')).match(/[^#:](\S+)/i);
if(page)
{
	page = $A(page)[0];	
}
	


window.addEvent('domready',function(){
	

	if(FlashDetect.installed && FlashDetect.major > 9 && (window.location.hash).indexOf('forcefallback') == -1)
	{
		$('flashbox').setStyles({
			width : '100%',
			height : '100%',
			display : 'block'
		});
		
		var obj = new Swiff('smloader.swf?please='+$random(1,99999999999), {
			id: 'myBeautifulMovie',
			width: '100%',
			height: '100%',
			params: {
				wmode: 'opaque',
				bgcolor: '#ffffff',
				allowScriptAccess : 'sameDomain'
			},
			vars: {
				pageToShow: page,
				lol : 'ASDF'
			}
		}).inject('flashbox');
	}
	else
	{
		new Element('link',{
			type : 'text/css',
			href : 'css/fonts.css',
			media : 'screen',
			rel : 'stylesheet'
		}).inject($$('head')[0]);
		$(document.body).addClass('noflash');
		fixPositions();
		if(page){
			if($$('a.'+page+'-inactivedarkcolor').length == 1)
			{
				$$('a.'+page+'-inactivedarkcolor')[0].fireEvent('mouseenter').fireEvent('click');
			}
		}
	}

});

var openContent = null;

function fixPositions()
{
	var c = $(window).getSize();
	
	//$$('#Start ol')[0].setStyle('marginTop',c.y - 600);
}

$('closeImp').addEvent('click',function($e){
	$e.stop();
	$('Impressum').morph({
		width : 0
	});
	$('closeImp').setStyle('display','none');

	$('impBox').set({
		tween : {
			onComplete : function(){
				
				this.subject.setStyle('display','none');
			}
		}}).tween('opacity',0);

		
	
});

$('showImp').addEvent('click',function($e){
	$e.stop();
	$('impBox').set({
		tween : {
			onComplete : function(){
				$('closeImp').setStyle('display','block');
			}
		},
		styles : {
			display : 'block',
			opacity : 0
		}}).tween('opacity', 0.8);
		
	$('Impressum').morph({
		width : 400
	});
});

$$('.closeLink').addEvent('click',function($e){
	$e.stop();
	window.location.hash = '';
	$(openContent).getChildren().each(function(item){
		item.tween('opacity',0);
	});
	
	var style = $$('ol .'+openContent+'-inactivedarkcolor')[0].getCoordinates();
	style.opacity = 0;
	$(openContent).setStyles({
			width : $(window).getSize().x,
			height : $(window).getSize().y
		}).set({ 
		morph : {
			onComplete : function(){
				this.subject.setStyle('display','none');
				var tmp = openContent;
				openContent = null;
				$$('ol .'+tmp+'-inactivedarkcolor')[0].fireEvent('mouseleave');
			}
		}}).morph(style);
	

});

$$('#Start ol a').addEvents({
	mouseenter : function($e){
		this.morph({
			backgroundColor : colors[this.retrieve('pg')].darkcolor,
			marginTop : this.retrieve('i') * 30 - 15
		});
	},
	mouseleave : function($e){
		if(this.retrieve('pg') == openContent)return;
		this.morph({
			backgroundColor : colors[this.retrieve('pg')].inactivedarkcolor,
			marginTop : this.retrieve('i') * 30
		});
	},
	click : function(){
		
		var style = this.getCoordinates();
		style.opacity = 0;
		style.display = 'block';
		
		openContent = this.retrieve('pg');
		
		$(this.retrieve('pg')).getChildren().setStyle('opacity',0);
		$(this.retrieve('pg')).setStyles(style).set({
			morph : {
				onComplete : function(){
					this.subject.getChildren().each(function(item){
						item.tween('opacity',1);
					});
					
					this.subject.setStyles({
						width : '100%',
						height : '100%'
					});
				}
			}
		}).morph({
			left : 0,
			top : 0,
			width : $(window).getSize().x,
			height : $(window).getSize().y,
			opacity : 1
			
						
		});
		
		
	}
}).each(function(item,i){

	item.store('pg',item.get('class').split('-')[0]);
	item.store('i',i);
	item.set({ morph : {
		duration : 277
	}});
});

$(window).addEvent('resize',fixPositions);


function setTitleAndHash(item){
	var basestr = 'SKIES & MEADOWS · Communication For Clean Tech Pioneers';
	if(item)
	{
		document.title = basestr + ' · ' + item;
		window.location.hash = '#'+item;
	}
	else
	{
		document.title = basestr;
		window.location.hash = '';		
	}
}

/*
Copyright (c) Copyright (c) 2007, Carl S. Yestrau All rights reserved.
Code licensed under the BSD License: http://www.featureblend.com/license.txt
Version: 1.0.4
*/
var FlashDetect = new function(){
    var self = this;
    self.installed = false;
    self.raw = "";
    self.major = -1;
    self.minor = -1;
    self.revision = -1;
    self.revisionStr = "";
    var activeXDetectRules = [
        {
            "name":"ShockwaveFlash.ShockwaveFlash.7",
            "version":function(obj){
                return getActiveXVersion(obj);
            }
        },
        {
            "name":"ShockwaveFlash.ShockwaveFlash.6",
            "version":function(obj){
                var version = "6,0,21";
                try{
                    obj.AllowScriptAccess = "always";
                    version = getActiveXVersion(obj);
                }catch(err){}
                return version;
            }
        },
        {
            "name":"ShockwaveFlash.ShockwaveFlash",
            "version":function(obj){
                return getActiveXVersion(obj);
            }
        }
    ];
    /**
     * Extract the ActiveX version of the plugin.
     * 
     * @param {Object} The flash ActiveX object.
     * @type String
     */
    var getActiveXVersion = function(activeXObj){
        var version = -1;
        try{
            version = activeXObj.GetVariable("$version");
        }catch(err){}
        return version;
    };
    /**
     * Try and retrieve an ActiveX object having a specified name.
     * 
     * @param {String} name The ActiveX object name lookup.
     * @return One of ActiveX object or a simple object having an attribute of activeXError with a value of true.
     * @type Object
     */
    var getActiveXObject = function(name){
        var obj = -1;
        try{
            obj = new ActiveXObject(name);
        }catch(err){
            obj = {activeXError:true};
        }
        return obj;
    };
    /**
     * Parse an ActiveX $version string into an object.
     * 
     * @param {String} str The ActiveX Object GetVariable($version) return value. 
     * @return An object having raw, major, minor, revision and revisionStr attributes.
     * @type Object
     */
    var parseActiveXVersion = function(str){
        var versionArray = str.split(",");//replace with regex
        return {
            "raw":str,
            "major":parseInt(versionArray[0].split(" ")[1], 10),
            "minor":parseInt(versionArray[1], 10),
            "revision":parseInt(versionArray[2], 10),
            "revisionStr":versionArray[2]
        };
    };
    /**
     * Parse a standard enabledPlugin.description into an object.
     * 
     * @param {String} str The enabledPlugin.description value.
     * @return An object having raw, major, minor, revision and revisionStr attributes.
     * @type Object
     */
    var parseStandardVersion = function(str){
        var descParts = str.split(/ +/);
        var majorMinor = descParts[2].split(/\./);
        var revisionStr = descParts[3];
        return {
            "raw":str,
            "major":parseInt(majorMinor[0], 10),
            "minor":parseInt(majorMinor[1], 10), 
            "revisionStr":revisionStr,
            "revision":parseRevisionStrToInt(revisionStr)
        };
    };
    /**
     * Parse the plugin revision string into an integer.
     * 
     * @param {String} The revision in string format.
     * @type Number
     */
    var parseRevisionStrToInt = function(str){
        return parseInt(str.replace(/[a-zA-Z]/g, ""), 10) || self.revision;
    };
    /**
     * Is the major version greater than or equal to a specified version.
     * 
     * @param {Number} version The minimum required major version.
     * @type Boolean
     */
    self.majorAtLeast = function(version){
        return self.major >= version;
    };
    /**
     * Is the minor version greater than or equal to a specified version.
     * 
     * @param {Number} version The minimum required minor version.
     * @type Boolean
     */
    self.minorAtLeast = function(version){
        return self.minor >= version;
    };
    /**
     * Is the revision version greater than or equal to a specified version.
     * 
     * @param {Number} version The minimum required revision version.
     * @type Boolean
     */
    self.revisionAtLeast = function(version){
        return self.revision >= version;
    };
    /**
     * Is the version greater than or equal to a specified major, minor and revision.
     * 
     * @param {Number} major The minimum required major version.
     * @param {Number} (Optional) minor The minimum required minor version.
     * @param {Number} (Optional) revision The minimum required revision version.
     * @type Boolean
     */
    self.versionAtLeast = function(major){
        var properties = [self.major, self.minor, self.revision];
        var len = Math.min(properties.length, arguments.length);
        for(i=0; i<len; i++){
            if(properties[i]>=arguments[i]){
                if(i+1<len && properties[i]==arguments[i]){
                    continue;
                }else{
                    return true;
                }
            }else{
                return false;
            }
        }
    };
    /**
     * Constructor, sets raw, major, minor, revisionStr, revision and installed public properties.
     */
    self.FlashDetect = function(){
        if(navigator.plugins && navigator.plugins.length>0){
            var type = 'application/x-shockwave-flash';
            var mimeTypes = navigator.mimeTypes;
            if(mimeTypes && mimeTypes[type] && mimeTypes[type].enabledPlugin && mimeTypes[type].enabledPlugin.description){
                var version = mimeTypes[type].enabledPlugin.description;
                var versionObj = parseStandardVersion(version);
                self.raw = versionObj.raw;
                self.major = versionObj.major;
                self.minor = versionObj.minor; 
                self.revisionStr = versionObj.revisionStr;
                self.revision = versionObj.revision;
                self.installed = true;
            }
        }else if(navigator.appVersion.indexOf("Mac")==-1 && window.execScript){
            var version = -1;
            for(var i=0; i<activeXDetectRules.length && version==-1; i++){
                var obj = getActiveXObject(activeXDetectRules[i].name);
                if(!obj.activeXError){
                    self.installed = true;
                    version = activeXDetectRules[i].version(obj);
                    if(version!=-1){
                        var versionObj = parseActiveXVersion(version);
                        self.raw = versionObj.raw;
                        self.major = versionObj.major;
                        self.minor = versionObj.minor; 
                        self.revision = versionObj.revision;
                        self.revisionStr = versionObj.revisionStr;
                    }
                }
            }
        }
    }();
};
FlashDetect.JS_RELEASE = "1.0.4";

