//Swedish,Finnish ÄäÖöÅå
//Russian АаБбВвГгДдЕеЁёЖжЗзИиЙйКкЛлМмНнОоПпРрСсТтУуФфХхЦцЧчШшЩщЪъЫыЬьЭэЮюЯя
$(function(){
	if ($('body').hasClass('ru')) {
		Cufon.set('fontFamily', 'Myriad Pro').replace('#text h1');
		Cufon.set('fontFamily', 'Myriad Pro Bold').replace('#sidebar li .change-font')('#header .menu li');
		Cufon.set('fontFamily', 'Myriad Pro').replace('.big-image p', {textShadow: '1px 1px #000'})('.sponsors-box p')('.interview-box h3');
		
	} else {
		if(!$('#text').hasClass('ru'))
			Cufon.set('fontFamily', 'GothamBook').replace('#text h1');
		Cufon.set('fontFamily', 'GothamMedium').replace('#sidebar li .change-font')('#header .menu li');
		Cufon.set('fontFamily', 'GothamBook').replace('.big-image p', {textShadow: '1px 1px #000'})('.sponsors-box p')('.interview-box h3')('.youtube-box h3');
	}
	
	Cufon.now();

	if ($('#youtube').length != 0)
	{
		loadYoutubeVideo($('.youtube-box a').attr('href'));
	}

	//Gallery
	if ($('.gallery').length != 0)
	{
		$('a[rel=lightbox]').fancybox({
			margin: 40,
			overlayOpacity: 0.7,
			overlayColor: '#000',
			showNavArrows: false,
			showCloseButton: false,
			titlePosition: 'inside',
			titleFormat: fancyboxTitle
		});

		$('a[rel=materialbox]').fancybox({
			margin: 40,
			overlayOpacity: 0.7,
			overlayColor: '#000',
			showNavArrows: true,
			showCloseButton: true,
                        showTitle: false
		});
		$('a[rel=videobox]').fancybox({
			margin: 10,
                        width: 848,
                        height: 480,
			overlayOpacity: 0.7,
			overlayColor: '#000',
			showNavArrows: false,
			showCloseButton: true,
                        showTitle: false
		});

		$('.lightboxtext .close a, .dialog a.cancel').live('click', function(){
			parent.$.fancybox.close();
			return false;
		})
		
		//also should add some function to change original image download url... .dialog .options a.accept
		$('a[rel=dialogbox]').live('mouseover', function(){
			href = $(this).attr('class');
			$(this).fancybox({
				overlayOpacity: 0.7,
				overlayColor: '#000',
				showNavArrows: false,
				showCloseButton: false,
				onComplete: function() {
					$('.dialog .options a.accept').attr('href', href);
				}
			});
		})
		
		$('.dialog .options a.accept').live('click', function(){
			parent.$.fancybox.close();
		})
		
	}
})

function fancyboxTitle(title, currentArray, currentIndex) {
	
	lightboxtext = '<div class="lightboxtext">';
	lightboxtext += $('.gallery .text').eq(currentIndex).html();
	lightboxtext += '<div class="close"><a href="#">Sulje x</a></div>';
	lightboxtext += '</div>';

	return lightboxtext;
	
}

function loadYoutubeVideo(url) {
    results = url.match("[\\?&]v=([^&#]*)");
    vid = results[1];
	
    $('#youtube').flash({
        swf: 'http://www.youtube.com/v/'+ vid,
        width: 216,
        height: 132,
        params: {
            allowscriptaccess: 'always',
            allowFullScreen: 'true'
        }
    });
}