function tooltipsIni(elementsSelector)
{
	jQuery(elementsSelector).tooltip
	(
		{
			delay: 0,
			track: true,
			showURL: false
		}
	);
};

function myCarouselIni()
{
	jQuery
	(
		function()
		{
		    jQuery(".slider").jMyCarousel
			(
				{
		        	visible: '100%',
			        auto: true,
			        speed: 1500
		    	}
			);
		}
	);
	
	jQuery
	(
		function()
		{
		    jQuery("#album_slider").jMyCarousel
			(
				{
			        btnPrev: jQuery('#prevAlbum'),
    			    btnNext: jQuery('#nextAlbum'),
		        	visible: '6',
			        auto: false,
			        speed: 300,
					eltByElt: true,
					evtStart : 'click',
					evtStop : 'click',
					circular: true
		    	}
			);
		}
	);
	
	jQuery
	(
		function()
		{
		    jQuery("#partners_slider").jMyCarousel
			(
				{
		        	visible: '100%',
			        auto: true,
			        speed: 3000
		    	}
			);
		}
	);
	
	
};

function getContacts(userId, frendId)
{
	jQuery('#add_contact_box').load('/get-contacts-'+userId+'-'+frendId+'.html', null, showContactBox);
};

function showContactBox()
{
	cBox = jQuery('#add_contact_box');
	cBox.slideToggle('fast');
	cBox.click
	(
		function()
		{
			cBox.hide();
		}
	);
	tooltipsIni('#add_contact_box *[title]');
};

function addFrend(userId, frendId)
{
	jQuery('#add_contact_box').load('/add-frend-'+userId+'-'+frendId+'.html');
};

function getAlbums(photoId, userId, selectedAlbumId)
{
	globalPhotoId = photoId;
	jQuery('#mab'+photoId).load('/get-albums-'+userId+'-'+selectedAlbumId+'-'+photoId+'.html', null, showAlbumBox);
};

function showAlbumBox()
{
	jQuery('div.move_album_box').hide();

	aBox = jQuery('#mab'+globalPhotoId);
	
	aBox.css('left', aBox.parent().width()/2 - 64);
	
	aBox.slideToggle('fast');
	aBox.click
	(
		function()
		{
			aBox.hide();
		}
	);
	tooltipsIni('div.move_album_box *[title]');
};

/* -------------------------- */

function getContactsForMove(frendId, userId, selectedContactId)
{
	globalFrendId = frendId;
	jQuery('#mcb'+frendId).load('/get-mcontacts-'+userId+'-'+selectedContactId+'-'+frendId+'.html', null, showContactsForMoveBox);
};

function showContactsForMoveBox()
{
	jQuery('div.move_contact_box').hide();

	aBox = jQuery('#mcb'+globalFrendId);
	
	aBox.css('left', aBox.parent().width()/2 - 64);
	
	aBox.slideToggle('fast');
	aBox.click
	(
		function()
		{
			aBox.hide();
		}
	);
	tooltipsIni('div.move_contact_box *[title]');
};

/* -------------------------- */

function resizeImage(bbImage)
{
	if (jQuery(bbImage).width() > 500)
	{
		jQuery(bbImage).width(500);
	}
}

function bbImagesIni()
{
	jQuery('img.bb-image').onImagesLoad({itemCallback: resizeImage});
};

function monthFinish()
{
	alert('xxxxxxxxxxxxxxxxxxxxxx');
};



function mainSubMenuIni()
{
	var mainSubMenuTimer = null;

	function showMainSubMenu()
	{
		closeMainSubMenus();
		stopMainSubMenuTimer();
		mainSubMenuElement = jQuery(this).next();
		mainSubMenuElement.show();
		mainSubMenuElement.mouseover(stopMainSubMenuTimer);
	};

	function closeMainSubMenus()
	{
		jQuery('div.main_submenu').hide();
	};
	
	function startMainSubMenuTimer()
	{
		mainSubMenuTimer = window.setTimeout(closeMainSubMenus, 70);
	};
	
	function stopMainSubMenuTimer()
	{
		if (mainSubMenuTimer)
		{
			window.clearTimeout(mainSubMenuTimer);
			mainSubMenuTimer = null;
		};
	};

	jQuery('a.main_menu_a').mouseover(showMainSubMenu);
	jQuery('a.main_menu_a, div.main_submenu').mouseout(startMainSubMenuTimer);
}

function allIni()
{
	mainSubMenuIni();
	bbImagesIni();
	myCarouselIni();
//	tooltipsIni('a, input, textarea');
	jQuery('#countdown').countdown
	(
		{
			until: new Date(gtY, gtM - 1, 1),
			serverTime: new Date(stY, stM - 1, stD, stH, stMin, stS)
		}
	);
};

function selectRegion(selectElement, url)
{
	urlString = url.substr(0, url.lastIndexOf('/')+1);
	pageString = url.substr(url.lastIndexOf('/')+1);
	
	if (pageString != 'index.html') pageString = 'index.html';

	if (selectElement.value != '')
	{
		document.location = urlString+pageString+'?region='+selectElement.value;
	} else
	{
		document.location = urlString+pageString;
	}
	return false;	
};

function getCal(userId, date, tCalendarId, root, mode, out)
{
	jQuery('#'+tCalendarId).load(root+'/'+out+'vc-'+userId+'-'+date+'-'+mode+'.html', null, null);
};

jQuery(document).bind('ready', allIni);