//when page loads start standard functions
function initialize() {
	//replace external links with open in new window
	externalLinks();
}

window.onload = initialize;


function $import(src){
	var scriptElem = document.createElement('script');
  scriptElem.setAttribute('src',src);
	scriptElem.setAttribute('type','text/javascript');
	document.getElementsByTagName('head')[0].appendChild(scriptElem);
}


// import with a random query parameter to avoid caching
function $importNoCache(src){
	var ms = new Date().getTime().toString();
	var seed = "?" + ms; 
	$import(src + seed);
}


function externalLinks() {
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors .length; i++) {
		var anchor = anchors[i];
		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") {
			anchor.target = "_blank";
			anchor.title = (anchor.title != "") ? anchor.title+" (opens in a new window) ": "opens in a new window";
			anchor.className = (anchor.className != '') ? anchor.className+' external' : 'external';
//			anchor.onclick = 'javascript: pageTracker._trackPageview (\'/outgoing/'+anchor.href+'\');';
			var track = anchor.href;
			track = track.replace('http://','');
			anchor.onclick = function() { 
				pageTracker._trackPageview('/outgoing/'+track);
			}
		}
	}
}


function prepareInput(id,value)
{
	if(document.getElementById(id).value==value) document.getElementById(id).value='';
}


//jquery functions
$(document).ready(function() {
	initialize();

	var mydate = new Date();
	$("#year").html("&copy; Lamprell Marine " + mydate.getFullYear());

	$("#side-area.current-lang- li.tp-12:first").prepend("<li class=\"boat_type_motor\">THE FLEET - MOTOR</li>");
	$("#side-area.current-lang- li.tp-11:first").prepend("<li class=\"boat_type_sailing\">THE FLEET - SAILING</li>");

	$("#side-area.current-lang-es li.tp-12:first").prepend("<li class=\"boat_type_motor\">LA FLOTA - MOTOR</li>");
	$("#side-area.current-lang-es li.tp-11:first").prepend("<li class=\"boat_type_sailing\">LA FLOTA - SAILING</li>");

	$("#side-area.current-lang-de li.tp-12:first").prepend("<li class=\"boat_type_motor\">DIE FLOTTE - MOTOR</li>");
	$("#side-area.current-lang-de li.tp-11:first").prepend("<li class=\"boat_type_sailing\">DIE FLOTTE - SAILING</li>");

	$("#side-area.current-lang-ru li.tp-12:first").prepend("<li class=\"boat_type_motor\">&#1055;&#1072;&#1088;&#1082; &#1089;&#1091;&#1076;&#1086;&#1074; - MOTOR</li>");
	$("#side-area.current-lang-ru li.tp-11:first").prepend("<li class=\"boat_type_sailing\">&#1055;&#1072;&#1088;&#1082; &#1089;&#1091;&#1076;&#1086;&#1074; - SAILING</li>");

	if ( $(".editable-item").length < 1 ) {


		$("h3").each( function() {
			if($(this).html()=="Miss Kate") {
				$("#fleet-page #side-area").addClass("miss-kate");
			}

			if($(this).html()=="Time Flies") {
				$("#fleet-page #side-area").addClass("time-flys");
			}

			if($(this).html()=="Ibiza &amp; Formentera") {
				$("#fleet-page #side-area").addClass("ibiza");
			}

			if($(this).html()=="Mallorca") {
				$("#fleet-page #side-area").addClass("mallorca");
			}

			if($(this).html()=="Menorca") {
				$("#fleet-page #side-area").addClass("menorca");
			}
		});

		$("h1").flash(
			{ 
				src: "/flash/text-replace.swf", 
				wmode: "transparent",
				flashvars: { 
					css: [
						"* { color: #7F7F7F; font-size: 4.5em; text-align: center; }",
						"span { color: #7F7F7F; }",
						"a { color: #7F7F7F; text-decoration: none; }",
						"a:hover { text-decoration: underline; }"
					].join(" ")
				}
			},
			{ version: 7 },
			function(htmlOptions) {
				htmlOptions.flashvars.txt = this.innerHTML;
				this.innerHTML = "<div>"+this.innerHTML+"</div>";
				var $alt = $(this.firstChild);
				htmlOptions.height = $alt.height();
				htmlOptions.width = $alt.width();
				$alt.addClass("alt");
				$(this)
					.addClass("flash-replaced")
					.prepend($.fn.flash.transform(htmlOptions));
			}
		);


		$("h3").flash(
			{ 
				src: "/flash/text-replace.swf", 
				wmode: "transparent",
				flashvars: { 
					css: [
						"* { color: #7F7F7F; font-size: 4em; text-align: center; }",
						"span { color: #7F7F7F; }",
						"a { color: #7F7F7F; text-decoration: none; }",
						"a:hover { text-decoration: underline; }"
					].join(" ")
				}
			},
			{ version: 7 },
			function(htmlOptions) {
				htmlOptions.flashvars.txt = this.innerHTML;
				this.innerHTML = "<div>"+this.innerHTML+"</div>";
				var $alt = $(this.firstChild);
				htmlOptions.height = $alt.height();
				htmlOptions.width = $alt.width();
				$alt.addClass("alt");
				$(this)
					.addClass("flash-replaced")
					.prepend($.fn.flash.transform(htmlOptions));
			}
		);

		$("h4").flash(
			{ 
				src: "/flash/text-replace.swf", 
				wmode: "transparent",
				flashvars: { 
					css: [
						"* { color: #0B243A; font-size: 3.3em; text-align: center; }",
						"span { color: #0B243A; }",
						"a { color: #0B243A; text-decoration: none; }",
						"a:hover { text-decoration: underline; }"
					].join(" ")
				}
			},
			{ version: 7 },
			function(htmlOptions) {
				htmlOptions.flashvars.txt = this.innerHTML;
				this.innerHTML = "<div>"+this.innerHTML+"</div>";
				var $alt = $(this.firstChild);
				htmlOptions.height = $alt.height();
				htmlOptions.width = $alt.width();
				$alt.addClass("alt");
				$(this)
					.addClass("flash-replaced")
					.prepend($.fn.flash.transform(htmlOptions));
			}
		);

		$("h5").flash(
			{ 
				src: "/flash/text-replace.swf", 
				wmode: "transparent",
				flashvars: { 
					css: [
						"* { color: #0B243A; font-size: 2.5em; }",
						"span { color: #0B243A; }",
						"a { color: #0B243A; text-decoration: none; }",
						"a:hover { text-decoration: underline; }"
					].join(" ")
				}
			},
			{ version: 7 },
			function(htmlOptions) {
				htmlOptions.flashvars.txt = this.innerHTML;
				this.innerHTML = "<div>"+this.innerHTML+"</div>";
				var $alt = $(this.firstChild);
				htmlOptions.height = $alt.height();
				htmlOptions.width = $alt.width();
				$alt.addClass("alt");
				$(this)
					.addClass("flash-replaced")
					.prepend($.fn.flash.transform(htmlOptions));
			}
		);

		$("hr").each(function(){
			$(this).replaceWith("<p class=\"hr\">&nbsp;<\/p>");
		});

		$("#standard-page #carousel, #standard-page-with-navigation #carousel").jCarouselLite({
			btnNext: ".next",
			btnPrev: ".prev",
			auto: 3200
		});

		$("#fleet-page #carousel").jCarouselLite({
			btnNext: ".next",
			btnPrev: ".prev",
			auto: 3200,
			vertical: true
		});

		if ( $("#find-us-map").length > 0 ) {
			loadMap();
		}


	/*
		$("#name").click(function(){
			prepareInput('name','Your Name');
		});

		$("#companyName").click(function(){
			prepareInput('companyName','Company Name');
		});

		$("#email").click(function(){
			prepareInput('email','Email Address');
		});

		$("#telephoneNumber").click(function(){
			prepareInput('telephoneNumber','Telephone Number');
		});

		$("#message").click(function(){
			prepareInput('message','Your Message');
		});
*/

	}





});