﻿// common.js

// setting global application object
var APP = new Object;

// jQuery
if(typeof jQuery != 'undefined') {
	
	// loading application object
	APP.language = $('html').attr('xml:lang') || 'en';
	APP.shadowbox_skin = 'classic';
	APP.uri = 'http://t3template.connetation.at';
	
	// load shadowbox
	if(typeof Shadowbox != 'undefined') {
		Shadowbox.loadLanguage(APP.language, '/fileadmin/web/scripts/libraries/shadowbox/lang');
		Shadowbox.loadSkin(APP.shadowbox_skin, '/fileadmin/web/scripts/libraries/shadowbox/skin');
		
		// media opener (shadowbox)
		$(document).ready(function() {
			var players = new Object;
			
			// init shadowbox
			Shadowbox.init({
				skipSetup: true,
				animSequence: 'sync',			// you may also use 'wh' or 'hw'
				resizeDuration: 0.35,			// the duration in seconds of the resize animation
				fadeDuration: 0.35,				// the duration in seconds of the fading animation
				handleOversize: 'drag',			// you may also use 'none' or 'resize'
				modal: false,					// set this to true to disable closing shadowbox when clicking on the overlay
				displayNav: true,				// set this to false to disable the navigation
				continuous: false,				// set this to true to be able to jump to the first/last image form the end/start
				enableKeys: true,				// set this to false to disable keyboard interaction
				
				onOpen: function(element) {
					
				},
				onFinish: function(element) {
					
				},
				onChange: function(element) {
					
				},
				onClose: function(element) {
					
				}
			});
			
			// load dependent players
			$('a[rel^=media]').each(function() {
				
				// image
				if($(this).attr('href').match(/\.jpg|\.jpeg|\.gif|\.png|\.bmp$/i) && typeof players.img == 'undefined') {
					players.img = true;
					
					$.getScript('/fileadmin/web/scripts/libraries/shadowbox/player/shadowbox-img.js', function (data, status) {
						//alert(status);
					});
				
				// flash video
				} else if($(this).attr('href').match(/\.flv$/i) && typeof players.flv == 'undefined') {
					players.flv = true;
					
					$.getScript('/fileadmin/web/scripts/libraries/shadowbox/player/shadowbox-flv.js', function (data, status) {
						//alert(status);
					});
				
				// flash animation
				} else if($(this).attr('href').match(/\.swf$/i) && typeof players.swf == 'undefined') {
					players.swf = true;
					
					$.getScript('/fileadmin/web/scripts/libraries/shadowbox/player/shadowbox-swf.js', function (data, status) {
						//alert(status);
					});
				
				// windows media
				} else if($(this).attr('href').match(/\.wmv|\.wm|\.asf|\.avi|\.mpg|\.mpeg$/i) && typeof players.wmp == 'undefined') {
					players.wmp = true;
					
					$.getScript('/fileadmin/web/scripts/libraries/shadowbox/player/shadowbox-wmp.js', function (data, status) {
						//alert(status);
					});
				
				// apple quicktime
				} else if($(this).attr('href').match(/\.mov|\.dv|\.moov|\.movie|\.mp4$/i) && typeof players.qt == 'undefined') {
					players.qt = true;
					
					$.getScript('/fileadmin/web/scripts/libraries/shadowbox/player/shadowbox-qt.js', function (data, status) {
						//alert(status);
					});
				}
			});
			
			// open media with the shadowbox
			$('a[rel^=media]').click(function() {
				Shadowbox.open($(this).get(0));
				return false;
			});
		});
	}
	
	// load soundmanager
	if(typeof soundManager != 'undefined') {
		soundManager.url = '/fileadmin/web/scripts/libraries/soundmanager/';
		soundManager.debugMode = false;
		
		soundManager.defaultOptions = {
			'autoLoad': false,		// enable automatic loading (otherwise .load() will call with .play())
			'stream': true,			// allows playing before entire file has loaded (recommended)
			'multiShot': false		// let sounds "restart" or "chorus" when played multiple times..
		}
	}
	
	// default window opener (external)
	$(document).ready(function() {
		$('a[rel~=external]').click(function() {
			relation = $(this).attr('rel');
			
			if($(this).attr('href')) {
				options = '';
				
				address = $(this).attr('href');
				
				if(relation.match(/\[([0-9]{2,4})\,([0-9]{2,4})\]/)) {
					options += '';
					
					size = relation.split('[');
					size = size[1].replace(/\]/, '');
					size = size.split(',');
					
					options += 'width=' + size[0] + ', height=' + size[1] + ',left=200,top=200';
				}
				
				window.open($(this).attr('href'), '', options);
				
				return false;
			}
		});
	});
	
	// typo3 shortcut
	$(document).ready(function() {
		$(document).keyup(function(e) {
			if (e.which == 113) window.open('http://' + document.URL.split('/')[2] + '/typo3/');
		});
	});
}

// Prototype
if(typeof Prototype != 'undefined') {
	
}