function setTopKeyActive () {
	field2procc = document.getElementById("topsearchkey");
	if ( field2procc.value == '.. kulcsszó ..' ) {
		field2procc.value = '';
		field2procc.style.color = '#333333';
	}
}

function mp_switch(to) {
	var switch_img = document.getElementById("mp_switch_img");
	var pic_movie_container = document.getElementById("pic_movie_container");
	var sw_2_img_switch = document.getElementById("sw_2_img_switch");
	var sw_2_movie_switch = document.getElementById("sw_2_movie_switch");
	var img_movie_img_container = document.getElementById("img_movie_img_container");
	var img_movie_movie_container = document.getElementById("img_movie_movie_container");
	
	// form elements
	var img_movie_active = document.getElementById("img_movie_active");
	var img_fallback_color = document.getElementById("img_fallback_color");
	var movie_fallback_color = document.getElementById("movie_fallback_color");
	var img_movie_active_color = document.getElementById("img_movie_active_color");
	var img_movie_inactive_color = document.getElementById("img_movie_inactive_color");
	
	if ( to == 'img' ) {
		switch_img.src = 'pxs/pic_movie_tab/pic_active.jpg';
		img_fallback_color.value = img_movie_active_color.value;
		movie_fallback_color.value = img_movie_inactive_color.value;
		sw_2_img_switch.style.color = img_movie_active_color.value;
		sw_2_movie_switch.style.color = img_movie_inactive_color.value;
		img_movie_img_container.style.display = 'inline';
		img_movie_movie_container.style.display = 'none';
	} else if ( to == 'movie' ) {
		switch_img.src = 'pxs/pic_movie_tab/movie_active.jpg';
		img_fallback_color.value = img_movie_inactive_color.value;
		movie_fallback_color.value = img_movie_active_color.value;
		sw_2_img_switch.style.color = img_movie_inactive_color.value;
		sw_2_movie_switch.style.color = img_movie_active_color.value;
		img_movie_img_container.style.display = 'none';
		img_movie_movie_container.style.display = 'inline';
	}
}
/*
function img_thumb_scroll() {
	image_thumbs_inner = document.getElementById('image_thumbs_inner');
	image_thumbs_container = document.getElementById('image_thumbs_container');
	diff = image_thumbs_inner.offsetHeight - image_thumbs_container.offsetHeight;


	if ( diff > 0 ) {
		//alert(diff);
		image_thumbs_container.mousemove(function(e){
			var top = (e.pageY - image_thumbs_container.offset().top) * (diff) / image_thumbs_container.offsetHeight;
			image_thumbs_container.scrollTop(top);
		});
	}
	
}
*/

jQuery(function(){
	//Get our elements for faster access and set overlay width
	var div = jQuery('div#image_thumbs_container'),
		ul = jQuery('div#image_thumbs_inner'),
		padder = jQuery('div#image_thumbs_padder'),
		zoom_container = jQuery('div#zoom_img_container'),
		zoom_inner = jQuery('div#zoom_img_inner')
		//ulPadding = 15;
	
	//Get dims
	divHeight = div.height();
	zoom_containerWidth = zoom_container.width();
	zoom_containerHeight = zoom_container.height();

	//Remove scrollbars	
	div.css({overflow: 'hidden'});
	zoom_container.css({overflow: 'hidden'});

	//When user move mouse over menu
	div.mousemove(function(e){
		//As text is loaded ul width increases,
		//so we recalculate it each time
		var ulHeight = ul.height();
		if ( ulHeight > divHeight ) {
			padder.css( 'padding', '5px 0 5px 0' );
		}
		var top = (e.pageY - div.offset().top) * (ulHeight-divHeight) / divHeight;
		div.scrollTop(top);
	});
	
	zoom_container.mousemove(function(e){
		//As text is loaded ul width increases,
		//so we recalculate it each time
		var ulHeight = zoom_inner.height();
		var top = (e.pageY - zoom_container.offset().top) * (ulHeight-zoom_containerHeight) / zoom_containerHeight;
		zoom_container.scrollTop(top);
		
		var ulWidth = zoom_inner.width();
		var scleft = (e.pageX - zoom_container.offset().left) * (ulWidth-zoom_containerWidth) / zoom_containerWidth;
		zoom_container.scrollLeft(scleft);
	});
	
	zoom_container.mouseover(function(e){
		zoom_inner.fadeTo(300,1);
	});
	
	zoom_container.mouseout(function(e){
		zoom_inner.fadeTo(150,0.01);
	});
	
});

Array.prototype.exists = function(o) {
	for(var i = 0; i < this.length; i++) {
	   if(this[i] === o) {
		 return i;
	   }
	}
	return false;
}

function nextProdPic() {
	var curr_img = document.getElementById("current_img").value;
	var img_array = document.getElementById("img_array").value;
	
	var img_array_array = img_array.split("|");
	curr_index = img_array_array.exists(curr_img);
	
	if ( curr_index+1 == img_array_array.length ) {
		var go_index = 0;
	} else {
		var go_index = curr_index+1;
	}
	mainImage(img_array_array[go_index]);
}

function prevProdPic() {
	var curr_img = document.getElementById("current_img").value;
	var img_array = document.getElementById("img_array").value;
	
	var img_array_array = img_array.split('|');
	var curr_index = img_array_array.exists(curr_img);
	//alert(curr_index+1);
	if ( curr_index == 0 ) {
		var go_index = img_array_array.length-1;
	} else {
		var go_index = curr_index-1;
	}
	mainImage(img_array_array[go_index]);
}

function mainImage(newimg) {
	mimage = document.getElementById('pmimage');
	mimage.src = newimg + '.jpg';
	curr_filed = document.getElementById("current_img");
	if ( curr_filed ) {
		curr_filed.value = newimg;
	}
	
	zoom_img = document.getElementById("zoomzoom_img");
	if ( zoom_img ) {
		zoom_img.src = newimg + '_zoom.jpg';
	}
}

















function showSub(index) {
	for (i = 1; i <= 100; i++) {
		content = document.getElementById("alelem_" + i );
		if ( content ) {
			if (i == index) {
				if ( content.style.display == "inline" ) {
					content.style.display = "none";
				} else {
					content.style.display = "inline";
				}
			} else {
				content.style.display = "none";
			}
		}
	}
}

function openDocker(dockerName) {
	elem = jQuery('div#'+dockerName);
	container = jQuery('div#header_div');
	if (elem.height() < 200 ) {
		container.animate( { height: '200px' }, 150 );
    	elem.animate( { height: (200)+'px' }, 200 );
	} else {
		container.animate( { height: '100px' }, 150 );
		elem.animate( { height: (40)+'px' }, 150 );
	}
}
function showRequestForm() {
	elem = document.getElementById('request_form');
	if ( elem.style.display == 'none' ) {
		elem.style.display = 'inline';
		document.location = document.location+'#requform';
	} else {
		elem.style.display = 'none';
	}
}

function showProdEmailForm() {
	elem = document.getElementById('prod_email_form');
	if ( elem.style.display == 'none' ) {
		elem.style.display = 'inline';
	} else {
		elem.style.display = 'none';
	}
}

function showTheBatts() {
	elem = document.getElementById('batteries_div');
	if ( elem.style.display == 'none' ) {
		elem.style.display = 'inline';
	} else {
		elem.style.display = 'none';
	}
}

function showTheWrapps() {
	elem = document.getElementById('wrappers_div');
	if ( elem.style.display == 'none' ) {
		elem.style.display = 'inline';
	} else {
		elem.style.display = 'none';
	}
}

function addCommas(nStr) {
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + '.' + '$2');
	}
	return x1 + x2;
}

function startm (pic_id, pic_array) {
	var targetImageInput = document.getElementById('targetImage');
	var currenImageInput = document.getElementById('currentImage');
	var ImageSwap = document.getElementById('imageSwap');
	
	ImageSwap.value = pic_array;
	targetImageInput.value = pic_id;
	currenImageInput.value = 1;
	changeThumb ();
}

var timer;
function changeThumb () {
	var ImageSwap = document.getElementById('imageSwap');
	if ( ImageSwap.value.length > 3 ) {
		var targetImageInput = document.getElementById('targetImage');
		var currenImageInput = document.getElementById('currentImage');
		var myTarget = targetImageInput.value;
		var targetImage = document.getElementById(myTarget);
		//alert(targetImage);
		if ( targetImage.complete ) {
			var pics =  ImageSwap.value.split('|');
			var nextpic = pics[parseInt(currenImageInput.value)+1];
			if (nextpic) {
				targetImage.src = nextpic+"_list.jpg";
				currenImageInput.value = parseInt(currenImageInput.value)+1;
			} else {
				targetImage.src = pics[1]+"_list.jpg";
				currenImageInput.value = 1;
			}
		}
		
		timer = setTimeout("changeThumb()",800);
		
	} else {
		clearTimeout(timer);
	}
}

function endm () {
	var targetImageInput = document.getElementById('targetImage');
	var currenImageInput = document.getElementById('currentImage');
	var ImageSwap = document.getElementById('imageSwap');
	
	var targetImage = document.getElementById(targetImageInput.value);
	var pics =  ImageSwap.value.split('|');
	targetImage.src = pics[1]+"_list.jpg";
	
	clearTimeout(timer);
	
	targetImageInput.value = 0;
	currenImageInput.value = 0;
	ImageSwap.value = 0;
}


if (/msie/i.test (navigator.userAgent)) //only override IE
{
	document.nativeGetElementById = document.getElementById;
	document.getElementById = function(id)
	{
		var elem = document.nativeGetElementById(id);
		if(elem)
		{
			//make sure that it is a valid match on id
			if(elem.attributes['id'].value == id)
			{
				return elem;
			}
			else
			{
				//otherwise find the correct element
				for(var i=1;i<document.all[id].length;i++)
				{
					if(document.all[id][i].attributes['id'].value == id)
					{
						return document.all[id][i];
					}
				}
			}
		}
		return null;
	};
}



var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari",
			versionSearch: "Version"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			   string: navigator.userAgent,
			   subString: "iPhone",
			   identity: "iPhone/iPod"
	    },
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();
//alert(BrowserDetect.browser+' '+BrowserDetect.version);
