var IE='\v'=='v';
var IE6 = navigator.userAgent.toLowerCase().indexOf('msie 6') != -1;

$(document).ready(function(){
	$('.calendar').calendar();
	$('#index-slider').islider();
	$('#topbanners').topslider();
	$('.addons .sound').sound();
	$('.shop-item .photos').minislider();
	$('.shop-item .text').valign({height:188, top:-6});
	
	$('.text img').each(function(n, i) {
		if($(i).css('float') == 'right')
			$(i).addClass('align-right');

		if($(i).css('float') == 'left')
			$(i).addClass('align-left');
	});

	$('#top .search input').placeholder();
	
	$(".shop-item .button").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	600, 
		'speedOut'		:	200, 
		'overlayShow'	:	false,
		width: 605,
		height:400,
		type: 'iframe'
	});
	
	$(".lightbox").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	600, 
		'speedOut'		:	200, 
		'overlayShow'	:	true
	});
	
	$(".lightbox-shop").fancybox({
		'transitionIn'	:	'fade',
		'transitionOut'	:	'fade',
		'speedIn'		:	600, 
		'speedOut'		:	200, 
		'overlayShow'	:	true,
		titleShow: false
	});
	
	$('h2.slide').unbind('click').click(function(){
		var div = $(this).next('div.slide');
		if (div.size() == 0) return false;
		
		div.slideToggle({
			step: function(){
					$('#wrap, #side, #content').css({height:'auto'});
					var h = $('#content').height();
					$('#side').height(h);
					if ($('#wrap').height() < h)
						if ($('#index-slider').size() != 0) $('#wrap').height(h-376);
						else
							$('#wrap').height(h-85);
				}
		});
		$(this).toggleClass('slide-expand');
	}).click();
});

$(window).load(function(){
	// Разделение чисел на разряды
	$('.topcart-price, .price-body .price .count').each(function(i,e){
		var str = $(e).text();
		var out = str.replace(/(\d)(?=(\d\d\d)+([^\d]|$))/g, '$1 ');
		$(e).text(out);
	});
	
	// Шрифты
	Cufon.replace('#side .block h2');
	Cufon.replace('.page-title');
	Cufon.replace('.news-date');
	Cufon.replace('#cart .cart-link span');
	Cufon.replace('.price-body .price .count');
	Cufon.replace('.faq-title');
	
	// Фон
	$('#coolbg2').height($('#coolbg1').height()-640);
	
	// Растягиваем контент
	var h = $('#content').height();
	//if (IE) h+=12;
	/*
	$('#side').height(h);
	if ($('#wrap').height() < h)
		if ($('#index-slider').size() != 0) $('#wrap').height(h-376);
		else
			$('#wrap').height(h-85);
	
	*/
	var h = $('.page-title').height();
	$('.news-date').css('top', 18 + h);
});

function AddToBookmark(a) {
	title = document.title;
	url = document.location;
	try {
		window.external.AddFavorite(url, title);
	} catch (e) {
		try {
			window.sidebar.addPanel(title, url, "");
		} catch (e) {
			if( typeof (opera) == "object") {
				a.rel = "sidebar";
				a.title = title;
				a.url = url;
				return true;
			} else {
				alert('Для добавления страницы в Избранное нажмите Ctrl+D');
			}
		}
	}
	return false;
}

