﻿// opener.jquery.js

if(typeof jQuery != 'undefined') {
	
	// load shadowbox
	if(typeof Shadowbox != 'undefined') {
		
		// 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: 240,				// the startup height of the viewport
				initialWidth: 320,				// the startup width of the viewport
				handleOversize: 'resize',			// you may also use 'none' or 'resize'
				displayNav: true,				// set this to false to disable the navigation
				continuous: true,				// set this to true to be able to jump to the first/last image form the end/start
				enableKeys: false,				// set this to false to disable keyboard interaction
				displayCounter: false,
				counterType: 'default',
				counterLimit: 10,
				viewportPadding: 20,
				
				onOpen: function(element) {
					
				},
				
				onFinish: function(element) {
					
				},
				
				onChange: function(element) {
					
				},
				
				onClose: function(element) {
					
				}
			});
			
			// read all media links
			$('a[rel^=media]').add('.news-single-img a').add('a[href$=.mp4]').each(function() {
				
				// set gallery
				if(mode = $(this).attr('rel').match(/:(gallery|slideshow)\./i)) {
					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); 
		});
	}
}
