//<![CDATA[
//Ajax.Responders.register({
//	onCreate  : function(){if(Ajax.activeRequestCount >  0) AjaxLoaderFull('show');},
//	onComplete: function(){if(Ajax.activeRequestCount == 0) AjaxLoaderFull('hide');}
//});

function myItem(){
	this.Item={ID: "", Lat: "", Lng: "", Zoom: 0};
	this.Country              ={Name: "", Lat: "", Lng: "", Accuracy: 0, ISOCode: ""};
	this.AdministrativeArea   ={Name: "", Lat: "", Lng: "", Accuracy: 0};
	this.SubAdministrativeArea={Name: "", Lat: "", Lng: "", Accuracy: 0};
	this.Locality             ={Name: "", Lat: "", Lng: "", Accuracy: 0};
}


function GetGroupsIcon(Items){
	Items = parseInt(Items);
	var s = {w: 0, h:0};
	switch(true){
		case Items <10:
			s.w = 20;
			s.h = 20;
			break;
		case Items <100:
			s.w = 30;
			s.h = 30;
			break;
		case Items <1000:
			s.w = 40;
			s.h = 40;
			break;
		default:
			s.w = 50;
			s.h = 50;
	}
	// ICON
	var icon = new GIcon();
	icon.image = '/images/GMapsIcons/M02_' + Items + '.png';
	icon.iconSize = new GSize(s.w, s.h);
	icon.iconAnchor = new GPoint(parseInt(s.w / 2), parseInt(s.w / 2));
	return icon;
}

function GetArticleIcon(){
	// ICON
	var icon = new GIcon();
	icon.image = "/images/GMapsIcons/article.png";
//	icon.shadow = "/images/GMapsIcons/shadow.png";
	icon.iconSize = new GSize(20, 26);
//	icon.shadowSize = new GSize(50, 40);
	icon.iconAnchor = new GPoint(16, 26);
//	icon.infoWindowAnchor = new GPoint(1, 0);
//	icon.infoShadowAnchor = new GPoint(1, 0);
	return icon;
}

function GetAlbumIcon(){
	// ICON
	var icon = new GIcon();
	icon.image = "/images/GMapsIcons/album.png";
//	icon.shadow = "/images/GMapsIcons/shadow.png";
	icon.iconSize = new GSize(20, 26);
//	icon.shadowSize = new GSize(50, 40);
	icon.iconAnchor = new GPoint(3, 26);
//	icon.infoWindowAnchor = new GPoint(1, 0);
//	icon.infoShadowAnchor = new GPoint(1, 0);
	return icon;
}

function VotingStarsBig_White(id, average, isLocked){
	isLocked = (isLocked==1) ? true : false;
	return new Starbox(id, average, {
						 stars: 5
						 , buttons: 10
						 , max: 10
						 , overlay: 'big.png'
						 , ghosting: true
						 , locked: isLocked
						});
}

function VotingStarsBig_Green(id, average, isLocked){
	isLocked = (isLocked==1) ? true : false;
	return new Starbox(id, average, {
						 stars: 5
						 , buttons: 10
						 , max: 10
						 , overlay: 'big_green.png'
						 , ghosting: true
						 , locked: isLocked
						});
}

function VotingStarsSmall_White(id, average, isLocked){
	isLocked = (isLocked==1) ? true : false;
	return new Starbox(id, average, {
						 stars: 5
						 , buttons: 10
						 , max: 10
						 , overlay: 'default.png'
						 , ghosting: true
						 , locked: isLocked
						});
}

function VotingStarsExtraSmallWhite(id, average, isLocked){
	isLocked = (isLocked==1) ? true : false;
	return new Starbox(id, average, {
						 stars: 5
						 , buttons: 10
						 , max: 10
						 , overlay: 'ExtraSmallWhite.png'
						 , ghosting: true
						 , locked: isLocked
						});
}

function VotingStarsExtraSmallGreen(id, average, isLocked){
	isLocked = (isLocked==1) ? true : false;
	return new Starbox(id, average, {
						 stars: 5
						 , buttons: 10
						 , max: 10
						 , overlay: 'ExtraSmallGreen.png'
						 , ghosting: true
						 , locked: isLocked
						});
}

function VotingStarsExtraSmallDarkGray(id, average, isLocked){
	isLocked = (isLocked==1) ? true : false;
	return new Starbox(id, average, {
						 stars: 5
						 , buttons: 10
						 , max: 10
						 , overlay: 'ExtraSmallDarkGray.png'
						 , ghosting: true
						 , locked: isLocked
						});
}

function VotingStarsExtraSmall_333333(id, average, isLocked){
	isLocked = (isLocked==1) ? true : false;
	return new Starbox(id, average, {
						 stars: 5
						 , buttons: 10
						 , max: 10
						 , overlay: 'ExtraSmall_333333.png'
						 , ghosting: true
						 , locked: isLocked
						});
}

function VotingStarsExtraSmallLightGray(id, average, isLocked){
	isLocked = (isLocked==1) ? true : false;
	return new Starbox(id, average, {
						 stars: 5
						 , buttons: 10
						 , max: 10
						 , overlay: 'ExtraSmallLightGray.png'
						 , ghosting: true
						 , locked: isLocked
						});
}

function VotingStarsSmall_Green(id, average, isLocked){
	isLocked = (isLocked==1) ? true : false;
	return new Starbox(id, average, {
						 stars: 5
						 , buttons: 10
						 , max: 10
						 , overlay: 'default_green.png'
						 , ghosting: true
						 , locked: isLocked
						});
}

function VotingStarsBig_Gray(id, average, isLocked){
	isLocked = (isLocked==1) ? true : false;
	return new Starbox(id, average, {
						 stars: 5
						 , buttons: 10
						 , max: 10
						 , overlay: 'big_gray.png'
						 , ghosting: true
						 , locked: isLocked
						});
}

function VotingStarsSmall_Gray(id, average, isLocked){
	isLocked = (isLocked==1) ? true : false;
	return new Starbox(id, average, {
						 stars: 5
						 , buttons: 10
						 , max: 10
						 , overlay: 'default_gray.png'
						 , ghosting: true
						 , locked: isLocked
						});
}

function VotingStarsSmall_DarkGray(id, average, isLocked){
	isLocked = (isLocked==1) ? true : false;
	return new Starbox(id, average, {
						 stars: 5
						 , buttons: 10
						 , max: 10
						 , overlay: 'default_dark_gray.png'
						 , ghosting: true
						 , locked: isLocked
						});
}

function AddRating(event) {
	var timestamp = new Date(); //EVITA LA CACHE DEL FILE ;)
	new Ajax.Request('/ajax/aj.Ratings.php?T' + timestamp.getTime(), {
			asynchronous: true,
			method      : 'get',
			encoding    : 'UTF-8',
			parameters  : event.memo,
			onFailure   : function(rq){alert('Errore ' + rq.status + ' -- ' + rq.statusText);},
			onSuccess   : function(rq){
							if(!rq.responseText.isJSON()){alert('JSON: NOT A JSON RESPONSE.');return false;}
							var obj = rq.responseText.evalJSON();
							if(obj.ResultCode!=0){alert(obj.ResultTitle);return false;}
							//alert(obj.Message);
						}
	});
}

function AddComment(FrmName) {


	var timestamp = new Date(); //EVITA LA CACHE DEL FILE ;)
	new Ajax.Request('/ajax/aj.Comments.php?T' + timestamp.getTime(), {
			asynchronous: true,
			method      : 'get',
			encoding    : 'UTF-8',
			parameters  : $(FrmName).serialize(),
			onLoading   : function(rq){$('AddComment').hide();$('CommentLoading').show();},
			onComplete  : function(rq){$('CommentLoading').hide();$('AddComment').show();},
			onFailure   : function(rq){alert('Errore ' + rq.status + ' -- ' + rq.statusText);},
			onSuccess   : function(rq){
							if(!rq.responseText.isJSON()){alert('JSON: NOT A JSON RESPONSE.');return false;}
							var obj = rq.responseText.evalJSON();
							if(obj.ResultCode!=0){alert(obj.ResultTitle);return false;}
                                                        $('CommentText').value = '';
                                                        alert(obj.Message);
                                                        window.location.reload();
                        }
	});
}

function OpenLBPhotos(AlbumID, PhotoID){
	Lightview.show({
		href   : '/applets/LB_Photos.php',
		rel    : 'ajax',
		options: {
			width          : 960,
			height         : 600,
			closeButton    : false,
			ajax           : {
				method     : 'get',
				parameters : {AlbumID: AlbumID, PhotoID: PhotoID},
				evalScripts: true
			}
		}
	});
}

function OpenLBPlayLists(ContentID, ContentType){
	Lightview.show({
		href   : '/applets/LB_PlayLists.php',
		rel    : 'ajax',
		options: {
			autosize       : true,
			closeButton    : false,
			ajax           : {
				method     : 'get',
				parameters : {ContentID: ContentID, ContentType: ContentType},
				evalScripts: true
			}
		}
	});
}

LB_Photos=function()
{
	this.ID           = 0;
	this.AlbumID      = 0;
	this.Items        = [];
	this.CurrentPic   = 0;
	
	this.CurrentPage    = 0;
	this.LastPage       = 0;
	this.LastPageOffset = 0;
	
	this.ItemWidth    = 123;
	this.ItemsPerPage = 6;
}

LB_Photos.prototype =
{
	PicPrevious: function()
	{
		var NewPos = this.CurrentPic-1;
		if(NewPos<0) NewPos=this.Items.length-1;
		this.CurrentPic=NewPos;
		this.ShowCurrentPic();
	}

	, PicNext: function()
	{
		var NewPos = this.CurrentPic + 1;
		if(NewPos>this.Items.length-1) NewPos=0;
		this.CurrentPic=NewPos;
		this.ShowCurrentPic();
	}

	, ShowCurrentPic: function()
	{
                
		OpenLBPhotos(this.AlbumID ,this.Items[this.CurrentPic]);
	}

	, ScrollToCurrentPic: function()
	{
		this.LastPage       = Math.ceil(this.Items.length / this.ItemsPerPage) -1;
		var EmptySpaces = this.Items.length % this.ItemsPerPage
		this.LastPageOffset = (this.Items.length % this.ItemsPerPage > 0) ? (this.ItemsPerPage - this.Items.length % this.ItemsPerPage) * this.ItemWidth : 0;
		
		this.CurrentPage=Math.floor(this.CurrentPic/this.ItemsPerPage);
		var ScrollTo = this.CurrentPage * (this.ItemsPerPage * this.ItemWidth * -1);
		if(this.CurrentPage==this.LastPage) ScrollTo += this.LastPageOffset;
		new Effect.Move($('pagination_content_02'), {x: ScrollTo, y: 0, duration: 1, mode:'absolute'})
		//alert(ScrollTo);
	}

	, PagePrevious: function()
	{
		this.CurrentPage=(this.CurrentPage)<=0 ? this.LastPage : this.CurrentPage-1;
		var ScrollTo = this.CurrentPage * (this.ItemsPerPage * this.ItemWidth)* -1;
		if(this.CurrentPage==this.LastPage)ScrollTo += this.LastPageOffset;
		new Effect.Move($('pagination_content_02'), {x: ScrollTo, y: 0, duration: 1, mode:'absolute'})
	}
	
	, PageNext: function()
	{
		this.CurrentPage=(this.CurrentPage>=this.LastPage) ? 0 : this.CurrentPage+1;
		var ScrollTo = this.CurrentPage * (this.ItemsPerPage * this.ItemWidth) * -1;
		if(this.CurrentPage==this.LastPage)ScrollTo += this.LastPageOffset;
		new Effect.Move($('pagination_content_02'), {x: ScrollTo, y: 0, duration: 1, mode:'absolute'})
	}
	
	, ViewOnMap: function(ContinentUrl, Lat, Lng, Zoom)
	{
		if(window.location.href.indexOf('/' + ContinentUrl)> -1) // CURRENT PAGE
		{
			var point = new GLatLng(Lat, Lng);
			ChangeView('PhotoView', true);
			map.setCenter(point, Zoom);
			Lightview.hide();
		}
		else
		{
			Lightview.hide();
			window.location.href = '/' + ContinentUrl + '/#' + Lat + '_' + Lng + '_' + Zoom + '_P';
		}
	}
}

ScrollingAlbums=function()
{
	this.Handler      = null;
	this.Items        = 0;
	
	this.CurrentPage    = 0;
	this.LastPage       = 0;
	this.LastPageOffset = 0;
	
	this.ItemWidth    = 125;
	this.ItemsPerPage = 7;
}

ScrollingAlbums.prototype =
{
	Init: function()
	{
		this.LastPage       = Math.ceil(this.Items/this.ItemsPerPage)-1;
		this.LastPageOffset = (this.ItemsPerPage - this.Items % this.ItemsPerPage) * this.ItemWidth;
	}
	, PagePrevious: function()
	{
		this.CurrentPage=(this.CurrentPage)<=0 ? this.LastPage : this.CurrentPage-1;
		var ScrollTo = this.CurrentPage * (this.ItemsPerPage * this.ItemWidth)* -1;
		if(this.CurrentPage==this.LastPage) ScrollTo += this.LastPageOffset;
		//alert(ScrollTo);
		new Effect.Move($(this.Handler), {x: ScrollTo, y: 0, duration: 1, mode:'absolute'});
	}
	
	, PageNext: function()
	{
		var LastPage = Math.ceil(this.Items/this.ItemsPerPage)-1;
		this.CurrentPage=(this.CurrentPage>=this.LastPage) ? 0 : this.CurrentPage+1;
		var ScrollTo = this.CurrentPage * (this.ItemsPerPage * this.ItemWidth)* -1;
		if(this.CurrentPage==this.LastPage) ScrollTo += this.LastPageOffset;
		//alert(ScrollTo);
		new Effect.Move($(this.Handler), {x: ScrollTo, y: 0, duration: 1, mode:'absolute'});
	}
}

function SetMapCenterToUrl(theMap, ViewMode){
	try
	{
		var point = theMap.getCenter();
		var anc ='#' + point.lat() + '_' + point.lng() + '_' + theMap.getZoom();
		switch(ViewMode){
			case 'FullView':
				anc += '_F';
				break;
			case 'PhotoView':
				anc += '_P';
				break;
		}
		location.href=anc;
	}
	catch(err){}
}

function Message ( subject, body ) {
    this.Subject = '[Info Request] - ' + subject;
    //this.Body    = body;
    this.Href    = 'mailto:info@abiyoyo.com?subject=' + encodeURIComponent(this.Subject);// + '&body=' + encodeURIComponent(this.Body);
}

function RequestInfo ( info, item ) {
    msg = new Message(info, 'Hi Abiyoyo,\n concerning this ' + item + ', I\'d like to...');
    location.href = msg.Href;
}

function AdsMail() {
    msg = new Message('Ads on Abiyoyo');
    /*msg.Body =
               'AZIENDA/Company: \n'
             + 'SETTORE/business area: \n'
             + 'CITTA\'/location: \n'
             + '________________\n\n'
             + 'SITO INTERNET/webpage: \n\n'
             + 'REFERENTE/Contact: \n\n'
             + 'TELEFONO/telephone: \n\n'
             + 'Note/notes: '*/
    location.href = msg.Href;
}

function checkEnter(e){ //e is event object passed from function invocation
	var characterCode; //literal character code will be stored in this variable
	if(e && e.which){ //if which property of event object is supported (NN4)
		e = e;
		characterCode = e.which; //character code is contained in NN4's which property
	}
	else{
		e = event;
		characterCode = e.keyCode; //character code is contained in IE's keyCode property
	}
	if(characterCode == 13){ //if generated character code is equal to ascii 13 (if enter key)
		return true;
	}
	else{
		return false;
	}

}
function StartFreeSearch(Text){
	new Ajax.Request('/ajax/aj.Common.php?T' + Math.random(),
			{
			asynchronous: true,
			method      : 'get',
			encoding    : 'UTF-8',
			parameters  : {Action : 'GetNormalizedText', Text : Text},
			onFailure   : function(rq){alert('Errore ' + rq.status + ' -- ' + rq.statusText);},
			onSuccess   : function(rq){
							if(!rq.responseText.isJSON()){alert('JSON: NOT A JSON RESPONSE.');return false;}
							var obj = rq.responseText.evalJSON();
							if(obj.ResultCode!=0){alert(obj.ResultTitle);return false;}
							location.href= '/tags/' + obj.NormalizedText
						}
			}
	);
}

//]]>