﻿// 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 sets = new Object;
			var links = new Array;
			
			// init shadowbox
			Shadowbox.init({
				skipSetup: true,
				animate: true,
				animateFade: true,
				animSequence: 'sync',			// type of animation used to open the viewport (sync, wh, hw)
				modal: false,					// set this to true to disable closing shadowbox when clicking on the overlay
				autoplayMovies: true,
				showMovieControls: true,
				resizeDuration: 0.35,			// the duration in seconds of the resize animation
				fadeDuration: 0.35,				// the duration in seconds of the fading animation
				initialHeight: 160,				// the startup height of the viewport
				initialWidth: 320,				// the startup width of the viewport
				handleOversize: 'drag',			// you may also use 'none' or 'resize'
				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
				displayCounter: true,
				counterType: 'default',
				counterLimit: 10,
				viewportPadding: 20,
				overlayOpacity: 0.8,
				
				onOpen: function(element) {
					
				},
				
				onFinish: function(element) {
					
				},
				
				onChange: function(element) {
					
				},
				
				onClose: function(element) {
					$('#header #campaign').show('slide', {direction: 'down'});
				}
			});
			
			// read all media links
			$('a[rel^=media]').each(function() {
				
				// set gallery
				//regexp ist falsch, es werden also keine galleries gerendert - KP 2010-01-31
				//if(mode = $(this).attr('rel').match(/\.(gallery|slideshow)-/i)) {
				if(mode = $(this).attr('rel').match('(gallery|slideshow)')) {
					title = $(this).attr('rel').split('.')[1];
					
					if(typeof sets[title] == 'undefined') {
						sets[title] = new Object();
						sets[title].title = title;
						sets[title].items = $('a[rel=' + $(this).attr('rel') + ']');
						sets[title].mode =mode[1];
					}
				} else {
					links.push($(this).get(0));
				}
			});
			
			// set up gallery items
			for(s in sets) {
				options = {
					gallery: sets[s].title,
					continuous: true,
					displayCounter: false
				};
				
				if(sets[s].mode == 'slideshow')
					options.slideshowDelay = 5;
				
				Shadowbox.setup(sets[s].items, options); 
			}
			
			// set up single media items
			if(links.length)
				Shadowbox.setup(links);
		});
	}
	
	// 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]').add('a[target=_blank]').click(function() {
			relation = $(this).attr('rel');
			
			if($(this).attr('href').match(/http:\/\/.*youtube.com\/v\//i)) {
				Shadowbox.open($(this).get(0), {
					height: 385,
					width: 640
				});
				
				return false;
			}
			
			if($(this).attr('href')) {
				options = '';
				
				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);
				if($(this).attr('href').match(/http:\/\/.*/))
				{
					window.open($(this).attr('href'), '', options);
				} else {
					window.open('http://'+ location.host + '/'+ $(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') {
	
}
