var slideshow, slideshow_curr, slideshow_element =[];
//Swedish,Finnish ÄäÖöÅå
//Russian АаБбВвГгДдЕеЁёЖжЗзИиЙйКкЛлМмНнОоПпРрСсТтУуФфХхЦцЧчШшЩщЪъЫыЬьЭэЮюЯя
//Lithuanian ĄČĘĖĮŠŲŪŽąčęėįšųūž
//Latvian ĀČĒĢĪĶĻŅŠŪŽāčēģīķļņšūž
//Estonian ŠšŽžÕõÄäÖöÜü
$(function(){

	fontFamily = ['OptimaLTStd', 'OptimaXBlackItalic'];

	if($('#container').is('.ru,.lv,.lt'))
		fontFamily = ['MyriadPro', 'MyriadProBoldItalic'];


	Cufon.set('fontFamily', fontFamily[0]).replace('#header h1', {textShadow: '1px 1px #000'})('.sponsors-box p')('.interview-box h3');

	Cufon.set('fontFamily', fontFamily[0]).replace('.products h3, #frontpage .widget h3', {textShadow: '1px 1px #003c4e'});
	Cufon.set('fontFamily', fontFamily[0]).replace('#frontpage .icecream-champion h3, #sidebar h1');

	Cufon.set('fontFamily', fontFamily[1]).replace('.new-products h3, .tabs-products .tabs a');
	Cufon.set('fontFamily', fontFamily[1]).replace('#text .product-picture p.see-other', {textShadow: '1px 1px #c93333'});

	Cufon.now();

	$('.search input.text')
		.click(function(){
			if($(this).val() == 'Otsi siit')
				$(this).val('');
		})
		.blur(function(){
		if($(this).val() == '')
			$(this).val('Otsi siit');
	})

	$('.see-other a').click(function(){
		$('.other-products-menu').toggle()

		return false;
	})

	$('.tabs-products .tabs a').click(function(){
		$(this).parents('ul').find('li').removeClass('active').removeClass('last-active')

		if($(this).parent().is(':last-child'))
			$(this).parent().addClass('active').addClass('last-active')
		else
			$(this).parent().addClass('active')

		Cufon.refresh();

		$(this).parents('.tabs-products').find('.tab-content').removeClass('active')

		$($(this).attr('href')).addClass('active')

		return false
	})

	$('.gallery a').fancybox({
		overlayOpacity: 0.65,
		overlayColor: '#000',
		titlePosition: 'inside',
		titleFormat: fancyboxTitle,
		showNavArrows: false
	});

	$('#fancybox-title .prev').live('click', function(){
		$.fancybox.prev()
	})

	$('#fancybox-title .next').live('click', function(){
		$.fancybox.next()
	})

	//$('#slideshow').cycle()

	$('.products .picture a').each(function(i){
		//console.info(i)
		timeout = i * 1000
		slideshow_element.push($(this))
		setTimeout ( "slideshow_element["+i+"].cycle({timeout: 3000})", timeout);
	})
	/*
		.mouseover(function(){
			if($(this).hasClass('active'))
			{
				clearTimeout(slideshow)
				return false
			}

			clearTimeout(slideshow)

			$(this)
				.addClass('active')
				.cycle({

					timeout: 500,
					autostop: 1
				})
				.cycle(1)
		})
		.mouseout(function(){
			slideshow_curr = $(this)
			slideshow = setTimeout ( "stopSlideshow()", 800);
		})
	*/
	$('.new-products .item, .product-list .picture').pngFix();
})

function stopSlideshow() {
	el = slideshow_curr;
	el.cycle(0).cycle('stop').removeClass('active')
}

function fancyboxTitle(title, currentArray, currentIndex){
	gallery_length = currentArray.length
	current_number = currentIndex + 1

	title_html = ''

	if(currentIndex != 0)
		title_html += '<a class="browse prev">Eelmine</a>';

	if(currentIndex != currentArray.length -1)
		title_html += '<a class="browse next">Edasi</a>';

	title_html += '<div class="title_text">' + title + '</div>';

	title_html += '<div class="image_of">Image ' + current_number + ' of ' + gallery_length + '</div>';

	return title_html;
}


