var cookie_domain = '.kuehne.nl';
var do_changes = true;
var dest_page = 0;

$(document).ready(function(){
	var flashvars = { xml_file: "/xml/bladertool.xml.php" };
	var params = { wmode:"transparent", allowScriptAccess: "sameDomain" };
	var attributes = { wmode:"transparent", allowScriptAccess: "sameDomain" };
	swfobject.embedSWF("/swf/digitalefolder-5.5.swf", "book", "810", "852", "8.0.0", "/swf/expressInstall.swf", flashvars, params, attributes);

	var flashvars = {};
	var params = { wmode:"transparent", allowScriptAccess: "sameDomain" };
	var attributes = { wmode:"transparent", allowScriptAccess: "sameDomain" };
	// swfobject.embedSWF("/swf/10107024_BAN_550x300_Book.swf?clickTAG=http://www.kuehne.nl/actie_delicious.xhtml", "magazine", "550", "300", "8.0.0", "/swf/expressInstall.swf", flashvars, params, attributes);

	$('#nav li a').click(function() {		
		$('#nav li a').removeClass('active');
		
		if ($(this).parent().hasClass('first')) {
			$.cookie("kuhne_fromPopup", true, {
				domain : cookie_domain,
				path : "/"
			});
		} else {
			$(this).addClass('active');
			do_changes = false;
			dest_page = $(this).attr('href');
			getFlashMovie("book").js_gotoPage(dest_page, false);
			return false;
		}
	});
});

function change_menu(page) {
	if (do_changes || page == dest_page) {
		$('#nav li a').removeClass('active');
		$('#nav li:nth-child(' + ((page/2)+1) + ') a').addClass('active');
		
		do_changes = true;
	}
}

function getFlashMovie(movieName) {
	var isIE = navigator.appName.indexOf("Microsoft") != -1;
	return (isIE) ? window[movieName] : document[movieName];
}		

/**
* jquery.cookie.js - rev 2
* Requires: jQuery 1.2+ 
* Author: Stephan van Opstal <stephan@netvlies.nl>
* Created: 2008-09-23 | Updated: 2008-09-24
* (This plugin is a rewrite of jquery.cookie.js by Klaus Hartl/klaus.hartl@stilbuero.de)
*
* Usage:
* $.cookie(cookiename, value, options);
*
* Examples:
* $.cookie('cookiename'); // get cookie
* $.cookie('cookiename', 'cookievalue'); // set cookie
* $.cookie('cookiename', null); // destroy cookie
* $.cookie('cookiename', 'cookievalue', { expire: 7 }); // destroy cookie after 7 days
* 
* Options:
* expire: integer // An expiry date after which it is no longer valid
* path: string // The path of the server it should be sent to
* domain: string // The domain it should be sent to
*/

(function($)
{
	$.cookie = function(name, value, options)
	{
		// set cookie
		if (typeof value != 'undefined')
		{
			// extend options
			options = options || {};
			
			// destroy cookie if value is set to null
			if (value === null) { options.expires = -1; }
			
			var cookieExpires = '';
		
			// only set expiration date if parameter was set
			if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString))
			{
	            if (typeof options.expires == 'number')
				{
	                var date = new Date();
	                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
	            }
				else
				{
	                var date = options.expires;
	            }
				
				var cookieExpires = '; expires=' + date.toUTCString();
			}
			
			var cookieName = name +'='+ encodeURIComponent(value);
			var cookiePath = options.path ? '; path=' + (options.path) : '';
			var cookieDomain = options.domain ? '; domain=' + (options.domain) : '';
			
			// write cookie
			document.cookie = cookieName + cookieExpires + cookiePath + cookieDomain;
		}
		// get cookie
		else
		{
			var cookieValue = null;
			
			if (document.cookie != '')
			{
				var cookies = document.cookie.split(';');

				for (var i=0; i<cookies.length; i++)
				{
					var cookie = $.trim(cookies[i]);
					
					// check if this is the correct cookie
					if (cookie.substring(0, name.length + 1) == (name + '='))
					{
						cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
						break;
					}
				}
			
				return cookieValue;
			}
		}
	};
})(jQuery);

