var lastValue = "";
var timeout = null;

function searchThis(value) {
		$('#search').liveSearch({ajaxURL: 'http://www.starsforeurope.com/search.html?lang=eng&search_folder=e4&raw='});
}

function onSearchKeyUp(value) {
	if(value.length >= 3) {
				//		show Loading animation
		jQuery('#loading').addClass('ajax-loading');
		jQuery('#search').liveSearch({ajaxURL: 'http://www.starsforeurope.com/search.html?lang=eng&search_folder=e4&raw='});
	}
}

function searchFor(value) {
	$("#search").keyup();
	document.getElementById("search").value = value;
	$("#search").keyup();
	return false;
}

function onFocusSearch(search) {
	if(search.value == search.defaultValue) {
		search.value = "";
		search.style.color = "#000";
	}
}

function onBlurSearch(search) {
	if(search.value == "") {
		search.value = search.defaultValue;
		search.style.color = "#999";
	}
}

function onScrollTop() {
	var top = document.documentElement.scrollTop;
	if(!top) top = window.pageYOffset;
	if(top > 2) {
		window.scrollTo(0, top / 2);
		setTimeout("onScrollTop()", 50);
	}
	else {
		window.scrollTo(0, 0);
	}
}

function setActive(n) {
		$(n).addClass("activearrow");
  $(n).parent().siblings().children().removeClass("activearrow");
}

function showImageLayer() {
	var imageText = document.getElementById("imagetext");
	if(imageText.style.visibility == "visible") {
		return;
	}
	var layer = document.getElementById("layer");
	var image = imageText.nextSibling;
	while(image.nodeType != 1) {
		image = image.nextSibling;
	}
	var imageHeight = parseInt(image.height);
	layer.style.height = imageHeight + "px";
	var list = layer.firstChild;
	while(list.nodeType != 1) {
		list = list.nextSibling;
	}
	list.style.top = Math.floor((imageHeight / 2) - (list.offsetHeight / 2)) + "px";
	layer.style.visibility = "visible";
	layer.parentNode.onmouseover = function(e) {
		var n = e ? e.target : window.event.srcElement;
		if(n != layer.parentNode) return;
		layer.style.visibility = "hidden";
		imageText.style.visibility = "hidden";
		layer.parentNode.onmouseover = function(){};
	};
}

function showImageText() {
	var layer = document.getElementById("layer");
	layer.style.visibility = "hidden";
	var imageText = document.getElementById("imagetext");
	var image = imageText.nextSibling;
	while(image.nodeType != 1) {
		image = image.nextSibling;
	}
	var imageHeight = parseInt(image.height);
	imageText.style.height = imageHeight + "px";
	var text = imageText.firstChild;
	while(text.nodeType != 1) {
		text = text.nextSibling;
	}
	text.style.height = (imageHeight - 40) + "px";
	imageText.style.visibility = "visible";
}

var scroll = false;

function startScrollLeft() {
	scroll = true;
	animateScrollLeft();
}

function stopScrollLeft() {
	scroll = false;
}

function animateScrollLeft() {
	if(!scroll) return;
	var thumbs = document.getElementById("thumbnails");
	var pos = thumbs.scrollLeft;
	if(pos > 0) {
		thumbs.scrollLeft = Math.max(0, pos - 8);
		setTimeout("animateScrollLeft()", 30);
	}
}

function startScrollRight() {
	scroll = true;
	animateScrollRight();
}

function stopScrollRight() {
	scroll = false;
}

function animateScrollRight() {
	if(!scroll) return;
	var thumbs = document.getElementById("thumbnails");
	var pos = thumbs.scrollLeft;
	var width = thumbs.scrollWidth - thumbs.offsetWidth - 4;
	if(pos < width) {
		thumbs.scrollLeft = Math.min(width, pos + 8);
		setTimeout("animateScrollRight()", 30);
	}
}

function scrollIntoView(thumb) {
	var thumbs = document.getElementById("thumbnails");
	var list = thumbs.childNodes;
	for(var l=list.length, i=0, p=0; i<l; i++) {
		if(list[i].nodeType != 1) {
			continue;
		}
		p += 69;
		var image = list[i].firstChild.firstChild;
		if(image.src.indexOf(thumb) != -1) {
			thumbs.scrollLeft = Math.max(0, (p - (69 * 5)));
			image.style.border = "1px solid #fff";
			break;
		}
	}
}


	$.fn.autoscroll = function() {
	 	pageTracker._trackPageview('/ajax/'+ window.location.pathname);
		jQuery('html,body').animate(
			{
				scrollLeft: this.offset().left,
				scrollTop: this.offset().top
			},
				800
			);
		return this;
	}; 

  function change_flash_content(title,link) {
	if (document.getElementById('player') != null) {
  		document.getElementById('player').SetVariable("change_content",link);
  		$('#stars').autoscroll();
	}
  	pageTracker._trackPageview('/ajax/player:'+ title);
	//console.log('/ajax/player:'+ title);
  }