var fv = {};
$(document).ready(function() {
	/* Event - product search on enter */
	$('#prodSearchField').keypress(function(event) {
		if(event.keyCode == '13') submitProdSearch();
	});
	
	$('.nyhedsbrevSignup').attr('href', 'http://eepurl.com/kyCw?keepThis=true&TB_iframe=true&height=300&width=400');
		   
	 /* Video thumbs */
	 
	var s = $('.thumbFlv');
	var counter = 0;


	s.each(
		function(a) {
			

			var content = this.innerHTML.split(";");
			var flashvars = {
				id: content[0],
				flv: content[1]
			};
			this.innerHTML='<div id="flvThumb_'+counter+'" style="height: 65px; width: 115px;">&nbsp;</div>';
			//a.id = "flvThumb_"+counter;
			swfobject.embedSWF("/spar.dk/flash/flvThumb.swf", "flvThumb_"+counter, 115, 65, "9.0.0", "/spar.dk/flash/expressInstall.swf", flashvars);
		//	this.show();
			counter++;
		}
	);
	
	
	
	var elms = $('ul.frontpageContent').children();
	elms.each(function(index, value) {
		switch(index) {
			case 0:
				var ch = $(value).children();
				var li = $(ch).children();
				li.each(function(a, b) {
					switch($(b).attr("class")) {
						case 'Image':
							fv.imageURL0=$(b).html();
						break;
						case 'Label':
							fv.label0 = escape($(b).text());
						break;
						case 'Color':
							fv.color0 = $(b).html();
						break;
						case 'Link':
							fv.link0 = escape($(b).text());
						break;
						case 'Target':
							fv.target0 = $(b).text();
						break;
					}
				});
			break;
			case 1:
				var ch = $(value).children();
				var li = $(ch).children();
				li.each(function(a, b) {
					switch($(b).attr("class")) {
						case 'Image':
							fv.imageURL1=$(b).html();
						break;
						case 'Label':
							fv.label1 = escape($(b).text());
						break;
						case 'Color':
							fv.color1 = $(b).html();
						break;
						case 'Link':
							fv.link1 = escape($(b).text());
						break;
						case 'Target':
							fv.target1 = $(b).text();
						break;
					}
				});
			break;
			case 2:
				var ch = $(value).children();
				var li = $(ch).children();
				li.each(function(a, b) {
					switch($(b).attr("class")) {
						case 'Image':
							fv.imageURL2=$(b).html();
						break;
						case 'Label':
							fv.label2 = escape($(b).text());
						break;
						case 'Color':
							fv.color2 = $(b).html();
						break;
						case 'Link':
							fv.link2 = escape($(b).text());
						break;
						case 'Target':
							fv.target2 = $(b).text();
						break;
					}
				});
			break;
			case 3:
				var ch = $(value).children();
				var li = $(ch).children();
				li.each(function(a, b) {
					switch($(b).attr("class")) {
						case 'Image':
							fv.imageURL3=$(b).html();
						break;
						case 'Label':
							fv.label3 = escape($(b).text());
						break;
						case 'Color':
							fv.color3 = $(b).html();
						break;
						case 'Link':
							fv.link3 = escape($(b).text());
						break;
						case 'Target':
							fv.target3 = $(b).text();
						break;
					}
				});
			break;
			case 4:
				var ch = $(value).children();
				var li = $(ch).children();
				li.each(function(a, b) {
					switch($(b).attr("class")) {
						case 'Image':
							fv.imageURL4=$(b).html();
						break;
						case 'Label':
							fv.label4 = escape($(b).text());
						break;
						case 'Color':
							fv.color4 = $(b).html();
						break;
						case 'Link':
							fv.link4 = escape($(b).text());
						break;
						case 'Target':
							fv.target4 = $(b).text();
						break;
					}
				});
			break;
			case 5:
				var ch = $(value).children();
				var li = $(ch).children();
				li.each(function(a, b) {
					switch($(b).attr("class")) {
						case 'Image':
							fv.imageURL5=$(b).html();
						break;
						case 'Label':
							fv.label5 = escape($(b).text());
						break;
						case 'Color':
							fv.color5 = $(b).html();
						break;
						case 'Link':
							fv.link5 = escape($(b).text());
						break;
						case 'Target':
							fv.target5 = $(b).text();
						break;
					}
				});
			break;
			case 6:
				var ch = $(value).children();
				var li = $(ch).children();
				li.each(function(a, b) {
					switch($(b).attr("class")) {
						case 'Image':
							fv.imageURL6=$(b).html();
						break;
						case 'Label':
							fv.label6 = escape($(b).text());
						break;
						case 'Color':
							fv.color6 = $(b).html();
						break;
						case 'Link':
							fv.link6 = escape($(b).text());
						break;
						case 'Target':
							fv.target6 = $(b).text();
						break;
					}
				});
			break;
			case 7:
				var ch = $(value).children();
				var li = $(ch).children();
				li.each(function(a, b) {
					switch($(b).attr("class")) {
						case 'Image':
							fv.imageURL7=$(b).html();
						break;
						case 'Label':
							fv.label7 = escape($(b).text());
						break;
						case 'Color':
							fv.color7 = $(b).html();
						break;
						case 'Link':
							fv.link7 = escape($(b).text());
						break;
						case 'Target':
							fv.target7 = $(b).text();
						break;
					}
				});
			break;
			case 8:
				var ch = $(value).children();
				var li = $(ch).children();
				li.each(function(a, b) {
					switch($(b).attr("class")) {
						case 'Image':
							fv.imageURL8=$(b).html();
						break;
						case 'Label':
							fv.label8 = escape($(b).text());
						break;
						case 'Color':
							fv.color8 = $(b).html();
						break;
						case 'Link':
							fv.link8 = escape($(b).text());
						break;
						case 'Target':
							fv.target8 = $(b).text();
						break;
					}
				});
			break;
			case 9:
				var ch = $(value).children();
				var li = $(ch).children();
				li.each(function(a, b) {
					switch($(b).attr("class")) {
						case 'Image':
							fv.imageURL9=$(b).html();
						break;
						case 'Label':
							fv.label9 = escape($(b).text());
						break;
						case 'Color':
							fv.color9 = $(b).html();
						break;
						case 'Link':
							fv.link9 = escape($(b).text());
						break;
						case 'Target':
							fv.target9 = $(b).text();
						break;
					}
				});
			break;
		}
	});
	swfobject.embedSWF("/eurospar/img/FrontPage.swf", "FrontpageFlash", "900", "298", "9.0", "/spar.dk/flash/expressInstall.swf", fv);
	
	// Gulpris pris label
	$('div.tilbudPris').each(function(index, val) {
		intWidth = 168;
		intHeight = 85;
		var contentAry = $(val).html().split(";");
		var str = $(val).html();
		maengde = contentAry[0];
		contentAry = contentAry[1].split(",");
		kr = contentAry[0];
		ore = contentAry[1];
		var flashvars = {
			kroner: kr,
			oerer: ore,
			maengde: maengde.replace(/^\s+|\s+$/g,"")
		};
		$(val).html("<div id='pris"+index+"' style=\"height: "+intHeight+"px; width: "+intWidth+"px;\">"+str+"</div>");
		swfobject.embedSWF("/spar.dk/flash/PrisFlash.swf", "pris"+index, intWidth, intHeight, "9.0.0", "/spar.dk/flash/expressInstall.swf", flashvars);
	});
});

if (typeof sIFR == "function") {
	sIFR.replaceElement(
		named(
		{
			sSelector: "div.green h2, div.blue h2, div.red h2, div.yellow h2, div#searchGul h2",
			sFlashSrc: "/img/fishmonger.swf",
			sColor: "#FFFFFF",
			sWmode: "transparent",
			sFlashVars: "textalign=center",
			sCase: "upper",
			nPaddingTop: 0,
			nPaddingBottom: 0
		})
	);
	sIFR.replaceElement(
		named(
		{
			sSelector: "div.content h1",
			sFlashSrc: "/img/fishmonger.swf",
			sColor: "#000000",
			sWmode: "transparent",
			sCase: "upper",
			nPaddingTop: 0,
			nPaddingBottom: 0
		})
	);
	
}

function openNyhedsbrevSignup(event)
{
	event.preventDefault();
	
	alert('');
	
	return false;
}

function submitProdSearch() {
	var searchStr = document.getElementById('prodSearchField').value;
	if(searchStr.length==0) {
		alert('Indtast sÃ¸geord');
	} else {
		document.location.href='?action=search&string='+searchStr;
	}
}

function thisMovie(movieName) {
	if (navigator.appName.indexOf("Microsoft") != -1) {
       return window[movieName];
   } else {
       return document[movieName];
   }
}
function videoClick(id) {
	thisMovie("video").playVideo(videos[id]['VideoFile']);
	
	document.getElementById("Name").innerHTML = videos[id]['Title'];
	document.getElementById("desc").innerHTML = videos[id]['Desc'];
	/*
	new Ajax.Request(
		'/AJAX/VideoLibrary.php',
		{
			parameters: {
				id: id
			},
			onComplete: function(trans) {
				json = eval("("+trans.responseText+")");
				thisMovie("video").playVideo(json.url);
				$('Name').update(json.name);
				$('desc').update(json.desc);
			}
		}
	);
	*/
}
function start_first_movie() {
	thisMovie("video").playVideo(videos[1]['VideoFile']);
}
