var profilesserver = 'http://recommend.fourhooks.ro/Service.svc/';
var bradserver = 'http://brad.fourhooks.ro/BradVoteService.svc/';

jQuery(document).ready(function($) {
	//search autosugest
	$('#search_auto_wrapper').mouseleave(function() {$(this).delay(2000).fadeOut(1000, function () {});});
	$('#searchinput').attr('autocomplete', 'off');
	$('#searchinput').typing({
		start: function (event, elem) {$('#searchbutton').attr('src', 'http://media.fourhooks.ro/metropotam/skin_metropotam2/scheme/search-loader.gif');},
		stop: function (event, elem) {var query = $(elem).attr('value'), search_auto = $('#search_auto_wrapper'); search_auto.show();search_auto.html(''); fSearchAutosugest(query, search_auto);},
		delay: 400
	});
	//menu
	$('#undeiesim_menu').mouseenter(function() {menuHideTabs();menuShowTab('undeiesim_tab');});
	$('#evenimente_menu').mouseenter(function() {menuHideTabs();menuShowTab('evenimente_tab');});
	$('#muzica_menu').mouseenter(function() {menuHideTabs();menuShowTab('muzica_tab');});
	$('#filme_menu').mouseenter(function() {menuHideTabs();menuShowTab('filme_tab');});
	$('#urban_menu').mouseenter(function() {menuHideTabs();menuShowTab('urban_tab');});
	$('#undeiesim_tab').mouseleave(function() {menuRemoveTab('undeiesim_tab');});
	$('#evenimente_tab').mouseleave(function() {menuRemoveTab('evenimente_tab');});
	$('#muzica_tab').mouseleave(function() {menuRemoveTab('muzica_tab');});
	$('#filme_tab').mouseleave(function() {menuRemoveTab('filme_tab');});
	$('#urban_tab').mouseleave(function() {menuRemoveTab('urban_tab');});
});

function menuRemoveTab(box_id) {var box = $('#' + box_id);box.delay(500).hide(10);}
function menuShowTab(box_id) {var box = $('#' + box_id);box.fadeIn(100, function () {box.show();});}
function menuHideTabs() {$('#undeiesim_tab').hide();$('#evenimente_tab').hide();$('#muzica_tab').hide();$('#filme_tab').hide();$('#urban_tab').hide();}
function fHideIndexRibbon() {$.getJSON(metropotamserver + 'hide_index_ribbon?callback=?', function(data) {$('#top_index2').mouseleave(function() {$(this).fadeOut(1000, function () {});});});}

function fJSEncode(value) {value = value.replace(/\\/g, '\\\\');value = value.replace(/\'/g, '\\\'');value = value.replace(/\"/g, '\\\"');return value}
function fHtmlEncode(value) {return $('<div />').text(value).html();} 
function fHtmlDecode(value) {return $('<div />').html(value).text();}

function setupWin(url, name, width, height) {w = window.open(url, name, "width=" + width + ",height=" + height + ",status=no,resizable=yes,menubar=no,location=no,scrollbars=yes"); w.focus();}

function trim(str) {var ret; if(typeof(str) != "string") str = str + ""; return str.replace(/(^\s+)|(\s+$)/gi, "");}

function checkNonEmpty(ctrl, errorMsg){
	var empty = true;
	var msg;
	if(typeof(ctrl) == "undefined") {alert("checkNonEmpty error: the field does not exists [" + ctrl.name + "]\n"); return false;}
	if(ctrl.type == "select-one" || ctrl.type == "select-multiple") empty = (ctrl.options[ctrl.selectedIndex].text == "");
	else empty = (trim(ctrl.value)=="");
	if(empty) {alert(errorMsg); ctrl.focus(); return false;}
	else return true;}

function checkNumeric(ctrl, errorMsg) {
	var i;
	var numeric = true;
	if(typeof(ctrl) == "undefined") {alert("checkNumeric error: the field does not exists [" + ctrl.name + "]\n"); return false;}
	if(ctrl.type != "text") {alert("checkNumeric error: the field is not a textbox [" + ctrl.name + "]\n"); return false;}
	for(i=0; i<ctrl.value.length; i++)
		if(ctrl.value.charAt(i) > "9" || ctrl.value.charAt(i) <"0") numeric = false;
	if(!numeric) {alert(errorMsg); ctrl.focus(); return false;}
	else return true;
}

function checkDate(ctrl, errorMsg) {
	var i;
	var isdate = true;
	var val;
	var dateparts;
	var intYear, intMonth, intDay;
	var daysInMonth = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
	var nDays;
	if(typeof(ctrl) == "undefined") {alert("checkDate error: the field does not exists [" + ctrl.name + "]\n"); return false;}
	if(ctrl.type != "text") {alert("checkDate error: the field is not a textbox [" + ctrl.name + "]\n"); return false;}
	val = ctrl.value;
	dateparts = val.split("/");
	if(dateparts.length != 3) isdate = false;
	else {
		intYear = dateparts[2];
		intMonth = dateparts[1];
		intDay = dateparts[0];
		if(!isNumeric(intYear) || !isNumeric(intMonth) || !isNumeric(intDay)) isdate = false;
		else {
			intYear = parseInt(intYear, 10);
			intMonth = parseInt(intMonth, 10);
			intDay = parseInt(intDay, 10);
			if(intYear <= 50) intYear += 2000;
			if(intYear >= 51 && intYear < 100) intYear += 1900;
			if(intMonth == 0 || intMonth > 12 || intDay == 0 || intYear > 9999) isdate = false;
			else {
				if (intMonth==2) nDays = ((intYear%4==0) && (!(intYear%100==0) || (intYear%400==0)))?29:28;
				else nDays = daysInMonth[intMonth-1];
				if(intDay > nDays) isdate = false;
			}
		}
	}
	if(!isdate) {alert(errorMsg); ctrl.focus(); return false;}
	else return true;
}

function isNumeric(str) {
	var numeric = true;
	for(var i=0; i<str.length; i++) if(str.charAt(i) > "9" || str.charAt(i) <"0") numeric = false;
	return numeric;
}

function isNumericSigned(str) {
	var i;
	var start = 0;
	var numeric = true;
	if (str.charAt(0)=="-" || str.charAt(0)=="+") start = 1;
	for(i=start; i<str.length; i++)
		if(str.charAt(i) > "9" || str.charAt(i) <"0") numeric = false;
	return numeric;
}

function fRateLocation(item, url, grade) {fRateThis(item, url, 'landmark', grade);}
function fRateArticle(item, url, grade) {fRateThis(item, url, 'article', grade);}
function fRateEvent(item, url, grade) {fRateThis(item, url, 'event', grade);}
function fRateVideo(item, url, grade) {fRateThis(item, url, 'video', grade);}
function fRateVideo2(item, url, grade) {fRateThis(item, url, 'video2', grade);}
function fRateArtist(item, url, grade) {fRateThis(item, url, 'band', grade);}
function fRateMovie(item, url, grade) {fRateThis(item, url, 'movie', grade);}
function fRatePerson(item, url, grade) {fRateThis(item, url, 'actor', grade);}
function fRateCity(item, url, grade) {fRateThis(item, url, 'city', grade);}
function fRateCountry(item, url, grade) {fRateThis(item, url, 'country', grade);}
function fRatePhoto(item, url, grade) {fRateThis(item, url, 'photo', grade);}
function fRateSnapshot(item, url, grade) {fRateThisBasic(item, url, 'snapshot', grade);}
function fRatePuzzle(item, url, grade) {fRateThisBasic(item, url, 'puzzle', grade);}

function fRateThisBasic(item, url, og_type, grade) {
	var container = $(item).parents('div.rating_box');
	container.html('<div class="location-loader"></div>');
	$.getJSON(url + 'rate_this_json?callback=?', {grade: grade}, function(data) {
		container.html('');
		var container_html = '';
		container_html += '<h5>' + data.message + '</h5><ul class="rating">';
		for (var i=0;i<data.stars.length;i++) container_html += '<li><img src="http://media.fourhooks.ro/metropotam/skin_metropotam2/scheme/star_' + data.stars[i] + '.gif" width="13" height="13" alt="" /></li>';
		container_html += '</ul>'
		container.html(container_html);
	});
}

function fRateThis(item, url, og_type, grade) {
	var container = $(item).parents('div.rating_box');
	container.html('<div class="location-loader"></div>');
	$.getJSON(url + 'rate_this_json?callback=?', {grade: grade}, function(data) {
		container.html('');
		var container_html = '';
		container_html += '<h5>' + data.message + '</h5><ul class="rating">';
		for (var i=0;i<data.stars.length;i++) container_html += '<li><img src="http://media.fourhooks.ro/metropotam/skin_metropotam2/scheme/star_' + data.stars[i] + '.gif" width="13" height="13" alt="" /></li>';
		container_html += '</ul>'
		container.html(container_html);
		if (data.grade>0) {
			var username = $("#fhchatname").html();
			var usernamehash = $("#fhchatinfo").html();
			$.getJSON(profilesserver + 'SetAction?callback=?', {username: username, usernamehash: usernamehash, actionname: 'rate', url: url, type: og_type, count: data.grade}, function(data) {});
		}
	});
}

function fListApplyBackground() {$(".location-item").hover(function () {$(this).attr('class', 'location-item location-item-on');}, function () {$(this).attr('class', 'location-item');});}
function fListPersonActions(item_id, url, comments) {
	$.getJSON(profilesserver + 'GetItemsInfo?callback=?', {urls: url}, function(data) {
		if (data.d.length>0) $('#' + item_id  + ' .location-actions').html('<div class="location-actions-bookmark"><a href="' + url + '" title="Vor sa-l vada">' + data.d[0]['bookmarked'] + '</a></div><div class="location-actions-like"><a href="' + url + '" title="Le-a placut">' + data.d[0]['like'] + '</a></div><div class="location-actions-been"><a href="' + url + '" title="L-au vazut">' + data.d[0]['seen'] + '</a></div>');
		else $('#' + item_id  + ' .location-actions').html('<div class="location-actions-bookmark"><a href="' + url + '" title="Vor sa-l vada">0</a></div><div class="location-actions-like"><a href="' + url + '" title="Le-a placut">0</a></div><div class="location-actions-been"><a href="' + url + '" title="L-au vazut">0</a></div>');
	});
}
function fListRandomPersons() {
	var container_items = $('#location-items');
	container_items.html('<div class="location-loader"></div>');
	$.getJSON($("head base").attr('href') + 'random_json?callback=?', function(data) {
		container_items.html('');
		for(var i=0; i<data.length; i++) {
			var item = data[i];
			var item_id = 'location-item-' + i;
			var item_html = '<div class="location-item" id="' + item_id + '">';
			item_html += '<div class="location-more"><a href="' + item.url + '">tu l-ai vazut?</a></div>';
			item_html += '<div class="location-info"><h3>';
			if (item.sticky==1) item_html += '<span class="hot">Hot</span>';
			item_html += '<a href="' + item.url + '" title="' + item.title + '" rel="permalink">' + item.title + '</a></h3>';
			if (item.thumb) item_html += '<div class="location-poster"><a href="' + item.url + '" title="' + item.title + '"><img src="' + item.thumb + '" alt="' + item.title + '" width="70" height="100" /></a></div>';
			item_html += '<p>' + item.details + '</p></div>';
			item_html += '<div class="location-actions"><div class="location-loader"></div></div>';
			item_html += '<div class="clear"><br /></div>';
			item_html += '</div>';
			container_items.append(item_html);
			fListPersonActions(item_id, item.url, item.comments);
		}
		fListApplyBackground();
	});
}
function fListMovieActions(item_id, url, comments) {
	$.getJSON(profilesserver + 'GetItemsInfo?callback=?', {urls: url}, function(data) {
		if (data.d.length>0) $('#' + item_id  + ' .location-actions').html('<div class="location-actions-bookmark"><a href="' + url + '" title="Vor sa-l vada">' + data.d[0]['bookmarked'] + '</a></div><div class="location-actions-like"><a href="' + url + '" title="Le-a placut">' + data.d[0]['like'] + '</a></div><div class="location-actions-been"><a href="' + url + '" title="L-au vazut">' + data.d[0]['seen'] + '</a></div>');
		else $('#' + item_id  + ' .location-actions').html('<div class="location-actions-bookmark"><a href="' + url + '" title="Vor sa-l vada">0</a></div><div class="location-actions-like"><a href="' + url + '" title="Le-a placut">0</a></div><div class="location-actions-been"><a href="' + url + '" title="L-au vazut">0</a></div>');
	});
}
function fListRandomMovies() {
	var container_items = $('#location-items');
	container_items.html('<div class="location-loader"></div>');
	$.getJSON($("head base").attr('href') + 'random_json?callback=?', function(data) {
		container_items.html('');
		for(var i=0; i<data.length; i++) {
			var item = data[i];
			var item_id = 'location-item-' + i;
			var item_html = '<div class="location-item" id="' + item_id + '">';
			if (item.review!='') item_html += '<div class="location-review"><a href="' + item.review + '"><img src="http://media.fourhooks.ro/metropotam/skin_metropotam2/scheme/badge-location-review-list.jpg" width="161" height="32" alt="Cronica Metropotam" /></a></div>';
			item_html += '<div class="location-more"><a href="' + item.url + '">tu l-ai vazut?</a></div>';
			item_html += '<div class="location-info"><h3>';
			if (item.sticky==1) item_html += '<span class="hot">Hot</span>';
			item_html += '<a href="' + item.url + '" title="' + item.title + '" rel="permalink">' + item.title + '</a></h3>';
			if (item.thumb) item_html += '<div class="location-poster"><a href="' + item.url + '" title="' + item.title + '"><img src="' + item.thumb + '" alt="' + item.title + '" width="70" height="100" /></a></div>';
			item_html += '<p>' + item.details + '</p></div>';
			item_html += '<div class="location-actions"><div class="location-loader"></div></div>';
			item_html += '<div class="clear"><br /></div>';
			item_html += '</div>';
			container_items.append(item_html);
			fListMovieActions(item_id, item.url, item.comments);
		}
		fListApplyBackground();
	});
}
function fSimilarLoadMovie(item_id, url) {
	var container_item = $('#' + item_id);
	$.getJSON(url + '/abstract_json_ex?callback=?', function(item) {
		var item_html = '';
		if (item.thumb) item_html += '<a href="' + item.url + '" title="' + item.title + '" rel="permalink"><img src="' + item.thumb + '" alt="' + item.title + '" width="120" height="180" /></a>';
		else item_html += '<a href="' + item.url + '" title="' + item.title + '" rel="permalink"><img src="http://media.fourhooks.ro/metropotam/images/movie-placeholder.gif" alt="' + item.title + '" width="120" height="180" /></a>';
		item_html += '<br /><a href="' + item.url + '" title="' + item.title + '" rel="permalink">' + item.title + '</a>';
		item_html += '<div class="clear"><br /></div>';
		container_item.html(item_html);
	});
}
function fListTopMovies(tag, limit) {
	var container_items = $('#location-items');
	$.getJSON(profilesserver + 'GetTopItems?callback=?', {type: 'movie', limit: limit, tags: tag}, function(data) {
		container_items.html('');
		for(var i=0; i<data.d.length; i++) {
			var box_id = 'location-item-' + (i+1);
			container_items.append('<div class="location-item" id="' + box_id + '"></div>');
			fLoadTopMovieBox(i+1, data.d[i]);
		}
		fListApplyBackground();
	});
}
function fLoadTopMovieBox(id, data) {
	$.getJSON(data['url'] + '/abstract_json_ex?callback=?', function(item) {
		var box_id = 'location-item-' + id;
		var box_html = '';
		if (item.review!='') box_html += '<div class="location-review"><a href="' + item.review + '"><img src="http://media.fourhooks.ro/metropotam/skin_metropotam2/scheme/badge-location-review-list.jpg" width="161" height="32" alt="Cronica Metropotam" /></a></div>';
		box_html += '<div class="location-more"><a href="' + data['url'] + '">tu l-ai vazut?</a></div>';
		box_html += '<div class="location-info" style="width:100%;">';
		box_html += '<h3><a href="' + data['url'] + '" title="' + item.title + '" rel="permalink">' + item.title + '</a></h3>';
		box_html += '<div class="location-actions" style="float:right;margin:18px 0 0 12px;"><div class="location-actions-bookmark"><a href="' + data['url'] + '" title="Vor sa-l vada">' + data['bookmarked'] + '</a></div><div class="location-actions-like"><a href="' + data['url'] + '" title="Le-a placut">' + data['like'] + '</a></div><div class="location-actions-been"><a href="' + data['url'] + '" title="L-au vazut">' + data['seen'] + '</a></div></div>';
		box_html += '<div style="float:left;font-size:30px;font-weight:bold;text-align:center;width:54px;margin:50px 12px 0 0;color:#c5c5c5;">' + id + '</div>';
		if (item.thumb) box_html += '<div class="location-poster"><a  href="' + data['url'] + '" title="' + item.title + '" rel="permalink"><img src="' + item.thumb + '" alt="' + item.title + '" width="70" height="100" /></a></div>';
		box_html += '<p>' + item.details + '</p>';
		box_html += '</div>';
		box_html += '<div class="clear"><br /></div>';
		$('#' + box_id).html(box_html);
	});
}
function fListArtistActions(item_id, url, comments) {
	$.getJSON(profilesserver + 'GetItemsInfo?callback=?', {urls: url}, function(data) {
		if (data.d.length>0) $('#' + item_id  + ' .location-actions').html('<div class="location-actions-bookmark"><a href="' + url + '" title="Vor sa asculte">' + data.d[0]['bookmarked'] + '</a></div></div><div class="location-actions-like"><a href="' + url + '" title="Le place">' + data.d[0]['like'] + '</a></div><div class="location-actions-been"><a href="' + url + '" title="Au ascultat">' + data.d[0]['seen'] + '</a></div>');
		else $('#' + item_id  + ' .location-actions').html('<div class="location-actions-bookmark"><a href="' + url + '" title="Vor sa asculte">0</a></div><div class="location-actions-like"><a href="' + url + '" title="Le place">0</a></div><div class="location-actions-been"><a href="' + url + '" title="Au ascultat">0</a></div>');
	});
}
function fListRandomArtists() {
	var container_items = $('#location-items');
	container_items.html('<div class="location-loader"></div>');
	$.getJSON($("head base").attr('href') + 'random_json?callback=?', function(data) {
		container_items.html('');
		for(var i=0; i<data.length; i++) {
			var item = data[i];
			var item_id = 'location-item-' + i;
			var item_html = '<div class="location-item" id="' + item_id + '">';
			item_html += '<div class="location-more"><a href="' + item.url + '">tie iti place?</a></div>';
			item_html += '<div class="location-info"><h3>';
			if (item.sticky==1) item_html += '<span class="hot">Hot</span>';
			item_html += '<a href="' + item.url + '" title="' + item.title + '" rel="permalink">' + item.title + '</a></h3>';
			if (item.thumb) item_html += '<div class="location-poster"><a href="' + item.url + '" title="' + item.title + '"><img src="' + item.thumb + '" alt="' + item.title + '" width="100" height="100" /></a></div>';
			item_html += '<p>' + item.details + '</p></div>';
			item_html += '<div class="location-actions"><div class="location-loader"></div></div>';
			item_html += '<div class="clear"><br /></div>';
			item_html += '</div>';
			container_items.append(item_html);
			fListArtistActions(item_id, item.url, item.comments);
		}
		fListApplyBackground();
	});
}
function fSimilarLoadArtist(item_id, url) {
	var container_item = $('#' + item_id);
	$.getJSON(url + '/abstract_json_ex?callback=?', function(item) {
		var item_html = '';
		if (item.thumb) item_html += '<a href="' + item.url + '" title="' + item.title + '" rel="permalink"><img src="' + item.thumb + '" alt="' + item.title + '" width="100" height="100" /></a>';
		else item_html += '<a href="' + item.url + '" title="' + item.title + '" rel="permalink"><img src="http://media.fourhooks.ro/metropotam/images/artist-placeholder.gif" alt="' + item.title + '" width="100" height="100" /></a>';
		item_html += '<br /><a href="' + item.url + '" title="' + item.title + '" rel="permalink">' + item.title + '</a>';
		item_html += '<div class="clear"><br /></div>';
		container_item.html(item_html);
	});
}
function fSimilarLoadArtistBasic(item_id, url) {
	var container_item = $('#' + item_id);
	$.getJSON(url + '/abstract_json_ex?callback=?', function(item) {
		var item_html = '<a href="' + item.url + '" title="' + item.title + '" rel="permalink">' + item.title + '</a>';
		container_item.html(item_html);
	});
}
function fListTopArtists(tag, limit) {
	var container_items = $('#location-items');
	$.getJSON(profilesserver + 'GetTopItems?callback=?', {type: 'band', limit: limit, tags: tag}, function(data) {
		container_items.html('');
		for(var i=0; i<data.d.length; i++) {
			var box_id = 'location-item-' + (i+1);
			container_items.append('<div class="location-item" id="' + box_id + '"></div>');
			fLoadTopArtistBox(i+1, data.d[i]);
		}
		fListApplyBackground();
	});
}
function fLoadTopArtistBox(id, data) {
	$.getJSON(data['url'] + '/abstract_json_ex?callback=?', function(item) {
		var box_id = 'location-item-' + id;
		var box_html = '';
		box_html += '<div class="location-more"><a href="' + data['url'] + '">tu ai ascultat?</a></div>';
		box_html += '<div class="location-info" style="width:100%;">';
		box_html += '<h3><a href="' + data['url'] + '" title="' + item.title + '" rel="permalink">' + item.title + '</a></h3>';
		box_html += '<div class="location-actions" style="float:right;margin:18px 0 0 12px;"><div class="location-actions-bookmark"><a href="' + data['url'] + '" title="Vor sa asculte">' + data['bookmarked'] + '</a></div><div class="location-actions-like"><a href="' + data['url'] + '" title="Le-a placut">' + data['like'] + '</a></div><div class="location-actions-been"><a href="' + data['url'] + '" title="Au ascultat">' + data['seen'] + '</a></div></div>';
		box_html += '<div style="float:left;font-size:30px;font-weight:bold;text-align:center;width:54px;margin:50px 12px 0 0;color:#c5c5c5;">' + id + '</div>';
		if (item.thumb) box_html += '<div class="location-poster"><a  href="' + data['url'] + '" title="' + item.title + '" rel="permalink"><img src="' + item.thumb + '" alt="' + item.title + '" width="100" height="100" /></a></div>';
		box_html += '<p>' + item.details + '</p>';
		box_html += '</div>';
		box_html += '<div class="clear"><br /></div>';
		box_html += '';
		$('#' + box_id).html(box_html);
	});
}
function fListLocationActions(item_id, url, comments) {
	$.getJSON(profilesserver + 'GetItemsInfo?callback=?', {urls: url}, function(data) {
		if (data.d.length>0) $('#' + item_id  + ' .location-actions').html('<div class="location-actions-comments"><a href="' + url + '/#comments" title="Comentarii">' + comments + '</a></div><div class="location-actions-like"><a href="' + url + '" title="Le-a placut">' + data.d[0]['like'] + '</a></div><div class="location-actions-been"><a href="' + url + '" title="Au fost acolo">' + data.d[0]['seen'] + '</a></div>');
		else $('#' + item_id  + ' .location-actions').html('<div class="location-actions-comments"><a href="' + url + '/#comments" title="Comentarii">' + comments + '</a></div><div class="location-actions-like"><a href="' + url + '" title="Le-a placut">0</a></div><div class="location-actions-been"><a href="' + url + '" title="Au fost acolo">0</a></div>');
	});
}
function fListRandomLocations() {
	var container_items = $('#location-items');
	container_items.html('<div class="location-loader"></div>');
	$.getJSON($("head base").attr('href') + 'random_json?callback=?', function(data) {
		container_items.html('');
		for(var i=0; i<data.length; i++) {
			var item = data[i];
			var item_id = 'location-item-' + i;
			var item_html = '<div class="location-item" id="' + item_id + '">';
			if (item.review!='') item_html += '<div class="location-review"><a href="' + item.review + '"><img src="http://media.fourhooks.ro/metropotam/skin_metropotam2/scheme/badge-location-review-list.jpg" width="161" height="32" alt="Cronica Metropotam" /></a></div>';
			item_html += '<div class="location-more"><a href="' + item.url + '">tu ai fost aici?</a></div>';
			item_html += '<div class="location-info"><h3>';
			if (item.ishot==1) item_html += '<span class="hot">Hot</span>';
			item_html += '<a href="' + item.url + '" title="' + item.title + '" rel="permalink">' + item.title + '</a></h3><p>' + item.details + '</p></div>';
			item_html += '<div class="location-actions"><div class="location-loader"></div></div>';
			item_html += '<div class="clear"><br /></div>';
			item_html += '</div>';
			container_items.append(item_html);
			fListLocationActions(item_id, item.url, item.comments);
		}
		fListApplyBackground();
	});
}
function fListLoadLocation(item_id, url) {
	var container_item = $('#' + item_id);
	$.getJSON(url + '/abstract_json_ex?callback=?', function(item) {
		var item_html = '';
		if (item.review!='') item_html += '<div class="location-review"><a href="' + item.review + '"><img src="http://media.fourhooks.ro/metropotam/skin_metropotam2/scheme/badge-location-review-list.jpg" width="161" height="32" alt="Cronica Metropotam" /></a></div>';
		item_html += '<div class="location-more"><a href="' + item.url + '">tu ai fost aici?</a></div>';
		item_html += '<div class="location-info"><h3>';
		if (item.ishot==1) item_html += '<span class="hot">Hot</span>';
		item_html += '<a href="' + item.url + '" title="' + item.title + '" rel="permalink">' + item.title + '</a></h3><p>' + item.details + '</p></div>';
		item_html += '<div class="location-actions"><div class="location-loader"></div></div>';
		item_html += '<div class="clear"><br /></div>';
		container_item.html(item_html);
		fListLocationActions(item_id, item.url, item.comments);
	});
}

function fSimilarLoadEvent(item_id, url) {
	var container_item = $('#' + item_id);
	$.getJSON(url + '/abstract_json?callback=?', function(item) {
		var item_html = '';
		if (item.thumb) item_html += '<a href="' + url + '" title="' + item.title + '" rel="permalink"><img src="' + item.thumb + '" alt="' + item.title + '" width="120" height="180" /></a>';
		else item_html += '<a href="' + url + '" title="' + item.title + '" rel="permalink"><img src="http://media.fourhooks.ro/metropotam/images/movie-placeholder.gif" alt="' + item.title + '" width="120" height="180" /></a>';
		item_html += '<br /><a href="' + url + '" title="' + item.title + '" rel="permalink">' + item.title + '</a>';
		item_html += '<div class="clear"><br /></div>';
		container_item.html(item_html);
	});
}
function fSimilarLoadIdbBasic(item_id, url) {
	var container_item = $('#' + item_id);
	$.getJSON(url + '/abstract_json?callback=?', function(item) {
		var item_html = '<a href="' + url + '" title="' + item.title + '" rel="permalink">' + item.title + '</a>';
		container_item.html(item_html);
	});
}

function fSimilarLoadVideo(item_id, url) {
	var container_item = $('#' + item_id);
	$.getJSON(url + '/abstract_json?callback=?', function(item) {
		var item_html = '';
		if (item.thumb) item_html += '<a href="' + url + '" title="' + item.title + '" rel="permalink"><img src="' + item.thumb + '" alt="' + item.title + '" width="120" height="90" /></a>';
		else item_html += '<a href="' + url + '" title="' + item.title + '" rel="permalink"><img src="http://media.fourhooks.ro/metropotam/images/video-placeholder.gif" alt="' + item.title + '" width="120" height="90" /></a>';
		item_html += '<br /><a href="' + url + '" title="' + item.title + '" rel="permalink">' + item.title + '</a>';
		item_html += '<div class="clear"><br /></div>';
		container_item.html(item_html);
	});
}

function fhHash() {
	this.length = 0;
	this.items = new Array();
	for (var i = 0; i < arguments.length; i += 2) {
		if (typeof(arguments[i + 1]) != 'undefined') {
			this.items[arguments[i]] = arguments[i + 1];
			this.length++;
		}
	}
	this.removeItem = function(in_key) {
		var tmp_previous;
		if (typeof(this.items[in_key]) != 'undefined') {
			this.length--;
			var tmp_previous = this.items[in_key];
			delete this.items[in_key];
		}
		return tmp_previous;
	}
	this.getItem = function(in_key) {
		return this.items[in_key];
	}
	this.setItem = function(in_key, in_value)
	{
		var tmp_previous;
		if (typeof(in_value) != 'undefined') {
			if (typeof(this.items[in_key]) == 'undefined') {
				this.length++;
			}
			else {
				tmp_previous = this.items[in_key];
			}
			this.items[in_key] = in_value;
		}
		return tmp_previous;
	}
	this.hasItem = function(in_key) {
		return typeof(this.items[in_key]) != 'undefined';
	}
	this.clear = function() {
		for (var i in this.items) {
			delete this.items[i];
		}
		this.length = 0;
	}
}

function fShowProfileVideo() {
	var dialog = $('#profile_demovideo_dialog');
	if (dialog.length>0) dialog.remove();
	var dlg_title = 'Profil de Metropotam';
	var dlg_html = '<object width="560" height="420"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=15749377&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=00ADEF&amp;fullscreen=1&amp;autoplay=1&amp;loop=0" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=15749377&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=00ADEF&amp;fullscreen=1&amp;autoplay=1&amp;loop=0" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="560" height="420"></embed></object>';
	$('<div id="profile_demovideo_dialog"></div>').html(dlg_html).dialog({autoOpen: true, modal: true, resizable: false, title: dlg_title, width: 640, minWidth: 640, height: 520, minHeight: 520});
	return false;
}

function fSearchAutosugest(query, search_auto) {
	if (query.length>2) {
		$.getJSON(searchserver + 'fhapiSearchAutosugest?callback=?', {query: query, howmany: 3}, function(data) {
			var locations = data.locations, events = data.events, movies = data.movies, actors = data.actors, bands = data.bands, content = data.content;
			if (locations.length>0 || events.length>0 || movies.length>0 || actors.length>0 || bands.length>0 || content.length>0) {
				search_auto.html('<div id="search_auto_container"><' + '/div>');
				var search_auto_container = search_auto.find('#search_auto_container');
				if (locations.length>0) {
					search_auto_container.append('<div id="search_auto_section_locations" class="search_auto_section"><div class="search_auto_section_title">Locuri<' + '/div><div class="search_auto_section_container"><ul><' + '/div><div class="clear"><br /><' + '/div><' + '/div>');
					var search_auto_section_container = search_auto_container.find('#search_auto_section_locations .search_auto_section_container ul');
					for(var i=0; i<locations.length; i++) {
						var title = locations[i].title + ' (' + locations[i].category + ')';
						var html = '<li><a href="' + locations[i].url + '" title="' + title + '">' + title + '<' + '/a><' + '/li>';
						search_auto_section_container.append(html);
					}
				}
				if (events.length>0) {
					search_auto_container.append('<div id="search_auto_section_events" class="search_auto_section"><div class="search_auto_section_title">Evenimente<' + '/div><div class="search_auto_section_container"><' + '/div><div class="clear"><br /><' + '/div><' + '/div>');
					var search_auto_section_container = search_auto_container.find('#search_auto_section_events .search_auto_section_container');
					for(var i=0; i<events.length; i++) {
						var title = events[i].title;
						var html = ''
						if (i<events.length-1) html = '<div class="search_auto_item search_auto_item_ex">';
						else html = '<div class="search_auto_item">';
						if (events[i].thumb) html += '<a href="' + events[i].url + '" title="' + title + '"><img src="' + events[i].thumb + '" width="18" height="25" alt="' + title + '" /><' + '/a>';
						else html += '<a href="' + events[i].url + '" title="' + title + '"><img src="http://media.fourhooks.ro/metropotam/images/event-placeholder.gif" width="18" height="25" alt="' + title + '" /><' + '/a>';
						html += '<div class="search_auto_item_body"><h3><a href="' + events[i].url + '" title="' + title + '">' + title + '<' + '/a><' + '/h3>';
						html += '<' + '/div><' + '/div>';
						search_auto_section_container.append(html);
					}
				}
				if (movies.length>0) {
					search_auto_container.append('<div id="search_auto_section_movies" class="search_auto_section"><div class="search_auto_section_title">Filme<' + '/div><div class="search_auto_section_container"><' + '/div><div class="clear"><br /><' + '/div><' + '/div>');
					var search_auto_section_container = search_auto_container.find('#search_auto_section_movies .search_auto_section_container');
					for(var i=0; i<movies.length; i++) {
						var title = movies[i].title;
						if (movies[i].release_year) title += ' (' + movies[i].release_year + ')';
						var html = ''
						if (i<movies.length-1) html = '<div class="search_auto_item search_auto_item_ex">';
						else html = '<div class="search_auto_item">';
						if (movies[i].thumb) html += '<a href="' + movies[i].url + '" title="' + title + '"><img src="' + movies[i].thumb + '" width="18" height="25" alt="' + title + '" /><' + '/a>';
						else html += '<a href="' + movies[i].url + '" title="' + title + '"><img src="http://media.fourhooks.ro/metropotam/images/movie-placeholder.gif" width="18" height="25" alt="' + title + '" /><' + '/a>';
						html += '<div class="search_auto_item_body"><h3><a href="' + movies[i].url + '" title="' + title + '">' + title + '<' + '/a><' + '/h3>';
						html += '<' + '/div><' + '/div>';
						search_auto_section_container.append(html);
					}
				}
				if (actors.length>0) {
					search_auto_container.append('<div id="search_auto_section_actors" class="search_auto_section"><div class="search_auto_section_title">Actori<br />si<br />regizori<' + '/div><div class="search_auto_section_container"><' + '/div><div class="clear"><br /><' + '/div><' + '/div>');
					var search_auto_section_container = search_auto_container.find('#search_auto_section_actors .search_auto_section_container');
					for(var i=0; i<actors.length; i++) {
						var title = actors[i].title;
						var html = ''
						if (i<actors.length-1) html = '<div class="search_auto_item search_auto_item_ex">';
						else html = '<div class="search_auto_item">';
						if (actors[i].thumb) html += '<a href="' + actors[i].url + '" title="' + title + '"><img src="' + actors[i].thumb + '" width="18" height="25" alt="' + title + '" /><' + '/a>';
						else html += '<a href="' + actors[i].url + '" title="' + title + '"><img src="http://media.fourhooks.ro/metropotam/images/person-placeholder.gif" width="18" height="25" alt="' + title + '" /><' + '/a>';
						html += '<div class="search_auto_item_body"><h3><a href="' + actors[i].url + '" title="' + title + '">' + title + '<' + '/a><' + '/h3>';
						html += '<' + '/div><' + '/div>';
						search_auto_section_container.append(html);
					}
				}
				if (bands.length>0) {
					search_auto_container.append('<div id="search_auto_section_bands" class="search_auto_section"><div class="search_auto_section_title">Artisti<br />si<br />trupe<' + '/div><div class="search_auto_section_container"><' + '/div><div class="clear"><br /><' + '/div><' + '/div>');
					var search_auto_section_container = search_auto_container.find('#search_auto_section_bands .search_auto_section_container');
					for(var i=0; i<bands.length; i++) {
						var title = bands[i].title;
						var html = ''
						if (i<bands.length-1) html = '<div class="search_auto_item search_auto_item_ex">';
						else html = '<div class="search_auto_item">';
						if (bands[i].thumb) html += '<a href="' + bands[i].url + '" title="' + title + '"><img src="' + bands[i].thumb + '" width="25" height="25" alt="' + title + '" /><' + '/a>';
						else html += '<a href="' + bands[i].url + '" title="' + title + '"><img src="http://media.fourhooks.ro/metropotam/images/artist-placeholder.gif" width="25" height="25" alt="' + title + '" /><' + '/a>';
						html += '<div class="search_auto_item_body"><h3><a href="' + bands[i].url + '" title="' + title + '">' + title + '<' + '/a><' + '/h3>';
						html += '<' + '/div><' + '/div>';
						search_auto_section_container.append(html);
					}
				}
				if (content.length>0) {
					search_auto_container.append('<div id="search_auto_section_content" class="search_auto_section"><div class="search_auto_section_title">Articole<br />si<br />video<' + '/div><div class="search_auto_section_container"><' + '/div><div class="clear"><br /><' + '/div><' + '/div>');
					var search_auto_section_container = search_auto_container.find('#search_auto_section_content .search_auto_section_container');
					for(var i=0; i<content.length; i++) {
						var title = content[i].title;
						var html = ''
						if (i<content.length-1) html = '<div class="search_auto_item search_auto_item_ex">';
						else html = '<div class="search_auto_item">';
						if (content[i].thumb) html += '<a href="' + content[i].url + '" title="' + title + '"><img src="' + content[i].thumb + '" width="25" height="25" alt="' + title + '" /><' + '/a>';
						html += '<div class="search_auto_item_body"><h3><a href="' + content[i].url + '" title="' + title + '">' + title + '<' + '/a><' + '/h3>';
						html += '<' + '/div><' + '/div>';
						search_auto_section_container.append(html);
					}
				}
				search_auto_container.append('<div id="search_auto_more" class="search_auto_more"><div class="search_auto_more_title">&nbsp;<' + '/div><div class="search_auto_more_container"><' + '/div><div class="clear"><br /><' + '/div><' + '/div>');
				var search_auto_more_container = search_auto_container.find('#search_auto_more .search_auto_more_container');
				search_auto_more_container.append('<a href="' + searchserver + '?query%3Autf8%3Austring=' + query + '" class="with_arrow red">vezi mai multe<' + '/a>');
			}
			$('#searchbutton').attr('src', 'http://media.fourhooks.ro/metropotam/skin_metropotam2/scheme/search.gif');
		});
	} else {
		$('#searchbutton').attr('src', 'http://media.fourhooks.ro/metropotam/skin_metropotam2/scheme/search.gif');
	}
}

function fLoadCommentsForm(url) {
	var container = $('#comments_form_body');
	container.html('');
	var html = '<form method="post" onsubmit="javascript:return docommsubmit();" action="' + url + '#preview">';
	html += '<div class="commenter_info">';
	html += '<h6><label for="author_name">numele</label> <span class="alert">*</span></h6>';
	html += '<input type="text" name="author_name:utf8:ustring" id="author_name" value="" />';
	html += '<h6><label for="author_email">email</label> <span class="alert">*</span></h6>';
	html += '<input type="text" name="author_email" id="author_email" value="" />';
	html += '<h6><label for="author_website">website/blog</label></h6>';
	html += '<input type="text" name="author_website" id="author_website" value="" />';
	html += '<img src="' + $("head base").attr('href') + 'getCaptchaRandomNumber?nocache=' + (Math.random()*100000) + '" border="0" width="100" height="20" alt="" />';
	html += '<h6><label for="word">scrie numarul</label> <span class="alert">*</span></h6>';
	html += '<input class="input" type="text" name="word" id="word" value="" />';
	html += '<span class="alert">*</span><span> campuri obligatorii</span>';
	html += '</div>';
	html += '<div class="commenter_post">';
	html += '<h6><label for="title">subiect</label></h6>';
	html += '<input class="comment_title" type="text" name="title:utf8:ustring" id="title" value="" />';
	html += '<h6><label for="body">comentarii</label> &nbsp; <strong id="commcounter">2000</strong> caractere din maxim 2000</h6>';
	html += '<textarea name="body:utf8:ustring" class="comment_body" id="body" cols="20" rows="10" onfocus="javascript:docommupdate();" onkeyup="javascript:docommupdate();"></textarea>';
	html += '<input type="radio" name="body_type" id="body_type0" value="0" checked="checked" /> <span><label for="body_type0">text</label></span>';
	html += '<input type="radio" name="body_type" id="body_type1" value="1" /> <span><label for="body_type1">html</label></span>';
	html += '<input type="checkbox" name="flg_notify" id="flg_notify" />';
	html += '<label for="flg_notify"><span>da-mi email cand se posteaza un comentariu nou</span></label>';
	html += '<div id="frm-submit-before"><input class="button_submit" name="submit-button" id="submit-button" type="submit" onclick="javascript:docommdisable();" value="Adauga" /></div>';
	html += '<div id="frm-submit-after" style="display:none;"><p class="red"><strong>Comentariul se adauga. Va rugam asteptati...</strong></p></div>';
	html += '</div>';
	html += '</form>';
	container.html(html);
	$('html, body').animate({scrollTop: container.offset().top}, 1000);
	$('#author_name').focus();
}

/*	present start	*/
$.extend({
	 getOrCreateDialog: function(id) {
		$box = $('#' + id);
		if (!$box.length) {
			$box = $('<div id="' + id + '"><p></p></div>').hide().appendTo('body');
		}
		return $box;
	 }		
});

function alert2(message, options) {
	var defaults = {
		modal		: true,
		resizable	: false,
		buttons		: {
			Ok: function() {
				$(this).dialog('close');
			}
		},
		show		: 'fade',
		hide		: 'fade',
		minHeight	: 50,
		dialogClass	: 'modal',
		title : 'Metropotam'
	}

	$alert = $.getOrCreateDialog('alert');	
	// set message
	$("p", $alert).html(message);
	// init dialog
	$alert.dialog($.extend({}, defaults, options));
}

function getPresent( elem)
{
	var qs = $(elem).attr("src").substring( $(elem).attr("src").indexOf( "?")+1);
	$.getJSON(profilesserver + "RetrievePresent?"+qs+"&callback=?", function(data) 
	{
		alert2( data.d);
	});
}

$(document).ready( function() {
	$(".present").each( function() {
		var username = $("#fhchatname").text();
		var id = $(this).attr( "alt").substring( 8);
		$(this).attr( "src", "http://recommend.fourhooks.ro/PresentImg.ashx?id="+id+"&username=" + username);
	});
});
/*	present end	*/

