// External Links
function externalLinks() {
	$("a[rel='external']").attr('target','_blank');
	$("#media_partners p a").attr('target','_blank');
}
// Print Page
function createPrintlink() {
	 $('#print-page > a').click (function() { window.print();});
}

// Email page - add pop-up behaviour
function emailPage() {
	emailpage_link = $('#email-page > a').attr('href');
	 $('#email-page > a').click (function() { 
		var randomnumber=Math.floor(Math.random()*101);
		windowname = 'emailwindow' + randomnumber;
		newwindow=window.open(emailpage_link,windowname,'width=570,height=440,top=15,left=15');
		return false;
	});
}
function insertFlash(base_url, movie, width, height) {
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="' + width + '" height="' + height + '">');
      document.write('<param name="movie" value="' + base_url + '/_flash/' + movie + '.swf" />');
	  document.write('<param name="wmode" value="transparent" />');
	  document.write('<param name="flashvars" value="siteroot='+ base_url + '" />');
      document.write('<param name="quality" value="best" />');
      document.write('<embed src="' + base_url + '/_flash/' + movie + '.swf"  quality="best" quality="best" flashvars="siteroot='+ base_url + '" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="' + width + '" height="' + height + '" wmode="transparent" />');
	document.write('</object>');
}
function insertExVideo(base_url, movie, width, height) {
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="' + width + '" height="' + height + '">');
      document.write('<param name="movie" value="' + base_url + '/exhibitor-files/video/' + movie + '" />');
	  document.write('<param name="wmode" value="transparent" />');
      document.write('<param name="quality" value="best" />');
      document.write('<embed src="' + base_url + '/exhibitor-files/video/' + movie + '"  quality="best"  swLiveConnect="true" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="' + width + '" height="' + height + '" wmode="transparent" />');
	document.write('</object>');
}

// EWL Sample - add pop-up behaviour
function popSample() {
	the_link = $('.viewsample1').attr('href');
	 $('.viewsample1').click (function() { 
		newwindow=window.open(the_link,'name','width=1010,height=500,top=15,left=5, scrollbars=yes');
		newwindow.focus();
		return false;
	});
	 
	 the_link2 = $('.viewsample2').attr('href');
	 $('.viewsample2').click (function() { 
		newwindow=window.open(the_link2,'name','width=1010,height=500,top=15,left=5, scrollbars=yes');
		newwindow.focus();
		return false;
	});
	 
	  the_link3 = $('.viewsample3').attr('href');
	 $('.viewsample3').click (function() { 
		newwindow=window.open(the_link3,'name','width=1010,height=500,top=15,left=5, scrollbars=yes');
		newwindow.focus();
		return false;
	});
}



// Reminder pop-up (for forgotten password)
function reminderPop() {
	remind_link = $('#reminder_link > a').attr('href');
	 $('#reminder_link > a').click (function() { 
		newwindow=window.open(remind_link, 'whatever','width=500,height=240,top=15,left=15');
		newwindow.focus();
		return false;
	});
}

// Terms & Conditions pop-up (for catalogue order form)
function tcPop() {
	tc_link = $('a#tcpop').attr('href');
	 $('#tcpop').click (function() { 
		newwindow=window.open(tc_link, 'traveller','width=530,height=440,top=15,left=15,scrollbars=yes');
		newwindow.focus();
		return false;
	});
}




function toggleNav() {
	
	 $('#mobmenu a').click (function() { 
	navref = document.getElementById("leftcol");
	if (navref.style.display == 'none') {
		// Show the nav
		$('#leftcol').slideDown('slow');
		$('#mobmenu a').html('Close');
	} else {
		$('#leftcol').slideUp('slow');
		$('#mobmenu a').html('Menu');
	}
		});
	
}

function toggleNav() {
	
	
	var myClass = $('body').attr("class");
	firstclass = myClass.substr(0,1);
  	if (firstclass == "i") {
		menutext = "Menu";
		closetext = "Chiudi";
	} else if (firstclass == "d") {
		menutext = "Menü";
		closetext = "Schließen";
	} else {
		menutext = "Menu";
		closetext = "Close";
	}
	 $('#mobmenu a').click (function() { 
	navref = document.getElementById("leftcol");
	if (navref.style.display == 'none') {
		// Show the nav
		$('#leftcol').slideDown('slow');
		$('#mobmenu a').html(closetext);
	} else {
		$('#leftcol').slideUp('slow');
		$('#mobmenu a').html(menutext);
	}
		});
	
}





function insertBanner(siteroot) {
	insertFlash(siteroot, 'banner_v2', 700, 201)
}	
function clearzeros() {
	$('.pamount input').focus(function() {
		q = $(this).val();
		if (q == "0") {
   			 $(this).val("");
		}
  	});
	$('.pamount input').blur(function() {
		q = $(this).val();
		if (q == "") {
   			 $(this).val("0");
		}
  	});
}

// Do these functions when DOM has loaded
$(document).ready(function() {
	createPrintlink();
	externalLinks();
	$("#tabbednav").idTabs();
	emailPage();
	toggleNav();
	reminderPop();
	popSample();
	tcPop();
	clearzeros();
	//$("#tabbednav").idTabs();
});

