var lang_code;
var char_href;
var file_href;
var subdomain = location.hostname.substr(0,3);
var testimonial_scroll;
if(subdomain == "www" || subdomain == "dll" || subdomain == "new"){
	lang_code = "en";
	char_href = "/dllindex/index-{CHAR}.shtml";
	file_href = "/dllindex/dll-files.shtml?{FILENAME}";
}
else{
	lang_code = location.hostname.substr(0,2);
	char_href = "/{CHAR}/";
	file_href = "/{FILENAME}.dll.html";
}
$(function(){
	setContentHeight();
	if($("#testimonial_text").height() > $("#testimonial_container").height()){
		addTestimonialScroll();
	}
	if($("#title_banner > .content").children("h1").height() > 41){
		$("#title_banner > .content").children("h1").css("top","40px");
	}
	$("#main_search_input").autocomplete({
		source: "/ajax/ajax.filelist.php",
		minLength: 2,
		select: function(e,ui){
			var filename_length = ui.item.label.length - 4;
			var filename = ui.item.label.substr(0,filename_length);
			var href = file_href.replace("{FILENAME}",filename);
			var file_location = location.protocol + "//" + location.hostname + href;
			//alert(new_location);
			window.location = file_location;
		}
	});
	$(window).resize(function() {
		setContentHeight();
	});
});
function addTestimonialScroll(){
	$("#testimonial_container").after("<div class=scroll_btns><p><a href='#' class=arrow id=testimonial_up>.</a> <a href='#' class=arrow id=testimonial_down>,</a></p></div>");
	$("#testimonial_up").hover(function(){
		testimonialScrollUp();
	},function(){
		testimonialScrollStop();
	});
	$("#testimonial_down").hover(function(){
		testimonialScrollDown();
	},function(){
		testimonialScrollStop();
	});
	$("#testimonial_up,#testimonial_down").click(function(){		
		return false;
	});
}
function testimonialScrollDown(){
	var current_pos = $("#testimonial_text").css("top");
	if(parseInt(current_pos) > parseInt($("#testimonial_container").height()) - parseInt($("#testimonial_text").height())){
		$("#testimonial_text").css("top","-=2");
	}
	testimonial_scroll = setTimeout("testimonialScrollDown()",10);
}
function testimonialScrollUp(){
	var current_pos = $("#testimonial_text").css("top");
	if(parseInt(current_pos) < 0){
		$("#testimonial_text").css("top","+=2");
	}
	testimonial_scroll = setTimeout("testimonialScrollUp()",10);
}
function testimonialScrollStop(){
	clearTimeout(testimonial_scroll);
}
function setContentHeight(){
	if($("body").height() < $(window).height()){
		var content_height = $(window).height() - $("#top").outerHeight() - $("#top_menu").outerHeight() - $("#title_banner").outerHeight() - $("#big_banner").outerHeight() - $("#search_bar").outerHeight() - $("#foot").outerHeight() - $("#bottom").outerHeight();
		$("#body").height(content_height);
	}
}
function alertDialog(content){
	var z = 1000;
	$("body").append("<div class=ui-widget-overlay></div>");
	$("body").append("<div class=alert_dialog><div class=x_icon><a href='#'>x</a></div><div class=body>"+content+"</div><div class=button><a href='#'>OK</a></div></div>");
	$(".alert_dialog > .x_icon").children("a").click(function(){
		$(this).parent().parent().remove();
		$("body > .ui-widget-overlay").remove();
		return false;
	});
	$(".alert_dialog > .button").children("a").click(function(){
		$(this).parent().parent().remove();
		$("body > .ui-widget-overlay").remove();
		return false;
	});
	$(".ui-widget-overlay").css("z-index",z);
	$(".ui-widget-overlay").width(function(i,w){
		return $("body").width();
	});
	$(".ui-widget-overlay").height(function(i,h){
		return $("body").height();
	});
	$(".alert_dialog").css({"left":function(i,v){
		return ($(window).width() - $(this).outerWidth())/2;
	},"top":function(i,v){
		return (($(window).height() - $(this).outerHeight())/2) + $(window).scrollTop();
	},"z-index":function(i,v){
		return z+1;
	}});
}
