jQuery.noConflict();
jQuery(function($) {
	$(window).bind('load', function () {
	    $('.slideshow').not('#getinspired .slideshow').cycle({
			fx: 'fade',
			containerResize: 1
		}).show();
	});
	
	if ($('body').hasClass('getinspired-start')) {
		$('body .page > .main').append($('<div/>').attr({id: 'audioplayer'}).addClass('audioplayer'));
		AudioPlayer.setup('/media/getinspired/player.swf', {width: 81, soundFile: '/media/getinspired/start.mp3', autostart: 'yes', transparentpagebg: 'yes'});
		AudioPlayer.embed('audioplayer');
	}
	
	$('.collectionExtended a[href="/megazine"]').addClass('megazineColorbox');
	
	$('.megazineColorbox').each(function (index, item) {
		$(item).data('filename', $(item).attr('title'));
		$(item).attr('title', $(item).text());
		$(item).colorbox({
			innerWidth: '1366px',
			innerHeight: '606px',
			onComplete: function () {
				megazineInit(jQuery(this).data('filename'));
			}
		});
		
	});
});

function megazineInit (filename) {
	var flashvars = {
		/*
			IMPORTANT: when only using one of the options below, REMOVE THE COMMA (,) at the end of the line.
						Otherwise this will break JavaScript (and thus the loading of the Flash content) in Internet Explorer.
						(Just make sure that the last of the enabled settings does not end with a comma).
			
			Remove the // in front of an option to enable it.
		*/
		
		/* This is the ABSOLUTE base that to use for all path resolving. This has an effect on ALL paths (including GUI, sounds etc). */
		
			//basePath: "http://www.pellepetterson.com/media/onlinekataloger/megazine/",
		basePath: "/media/onlinekataloger/megazine/",
		
		/* Used to pass the name of the xml file to use. Path is RELATIVE to basePath, or, if not set, to the megazine.swf file. */
		xmlFile: filename + '.mz3',
		
		/* When set to true, log messages are printed to the JavaScript console (using the console.log() function) */
		logToJsConsole: "true"
	};
	var params = {
		/* Determines whether to enable transparency (show HTML background). Not recommended (slow). Use book/background instead. */
		//wmode: "transparent",
		menu: "false",
		/* Necessary for proper scaling of the content. */
		scale: "noScale",
		/* Necessary for fullscreen mode. */
		allowFullscreen: "true",
		/* Necessary for SWFAddress and other JavaScript interaction. */
		allowScriptAccess: "always",
		/* This is the background color used for the Flash element. */
		bgcolor: "#333333"
	};
	var attributes = {
		/* This must be the same as the ID of the HTML element that will contain the Flash element. */
		id: "megazine"
	};
	/* Actually load the Flash. */
	swfobject.embedSWF("/media/megazine/preloader.swf", "megazine", "100%", "100%", "9.0.115", "/media/megazine/expressInstall.swf", flashvars, params, attributes);
}


jQuery(function($) {
	$(window).bind('load', function () {
		if($('a[title^="Americas"]')) {
			$('a[title^="Americas"]').click();
		}

		initNewsNavToggleGrayscale();
	});

	$('#newsContainer')
	.after('<ul id="newsNav" class="startPuffar">')
	.cycle({
		speed:  'fast', 
		timeout: 0, 
		pager:  '#newsNav' ,
		pagerAnchorBuilder: function(idx, slide) {
			var classes = ['puff'];

			var counter = idx + 1;
			if(counter == 1) {
				classes.push('first');
			}

			return '<li class="' + classes.join(' ') + '"><a href="#" mce_href="#"><img src="/media/news-puff-' + counter + '.jpg" border="0" /></a></li>'; 
		}
	});

	$('#newsNav a').click(function () {
		$('#newsNav a').removeClass('activeSlide');
		$(this).addClass('activeSlide');
		newsNavToggleGrayscale();
	});

	function newsNavToggleGrayscale(element) {
		$('#newsNav img, #newsNav canvas').each(function() {
			if($(this).parent('a').hasClass('activeSlide')) {
				Pixastic.revert(this);
			} else {
				Pixastic.process(this, 'desaturate', {average: false});
			}
		});
	}

	function initNewsNavToggleGrayscale() {
		if(pos = window.location.hash.split('-', 2).pop()) {
			pos -= 1;
			$('#newsNav li:eq(' + pos + ') a').click();
		}
	}
});

