/**
 * @author Cernos
 */

$(document).ready(function(){
	
	//Search Value Text
	var searchField = $('#search_field');
	var searchFieldValue = searchField.attr('value');
	searchField.focus(function(){
		if(searchField.attr('value') == searchFieldValue) searchField.attr({'value':''});
	});
	searchField.blur(function(){
		if(searchField.attr('value') == '') searchField.attr({'value':searchFieldValue});
	});
	
	if ($(".custom").attr('class') == 'custom'){	
		
		var obj = $(".custom");
		var objHeight= parseInt(obj.height());
		
		if(objHeight > 143){
			obj.addClass("cut");
			obj.append('<div class="hide"></div>');
			$(".hide",obj).css({"top":100});
		}
	
		//Вывод сокращенной статьи
		if ($(".custom a.full").attr('class') != 'full'){
			
			obj.append('<div class="button_gray full"><input type="button" value="Читать далее"></div><div class="button_gray short"><input type="button" value="Свернуть статью"></div>');
	
			//Разворачиваем
			$(".full",obj).click(function(){
				
				$(".button_gray.full").hide();
				$(".hide",obj).hide();
				
				height = obj.height();			
				obj.height("auto");		
			});
			
			//Сворачиваем
			$(".short",obj).click(function(){
				
				$(".button_gray.full").show();
				$(".hide",obj).show();
				
				obj.height(height);
				window.location = "#";
							
			});
		}else{			
			obj.append('<div class="button_gray full"><a href="'+$(".custom a.full").attr('href')+'" title="Читать далее"><input type="button" value="Читать далее" onclick="javascript:window.open(\''+$(".custom a.full").attr('href')+'\',\'new\',\'\');return false;"></a></div>');
			$(".button_gray",obj).css({"margin":"2px 0 5px 0"});
			$(".custom a.full").remove();
		}
	}
	
	//Order
	if($(".order").attr('class')=="order" && $("#error_block").attr("id") != "error_block"){		
		$(".order").hide()
		$(".order-button-cart").click(function(){
			$(".order").show();
			location.href="#order";
			return false;
		});
	}
	
	//LightBox
	$("a[rel=lightbox]").lightBox({
		fixedNavigation:true,
		imageBlank:    'http://fs.teplotorg.com.ua/images/lightbox/blank.gif',
		imageLoading:  'http://fs.teplotorg.com.ua/images/lightbox/loading.gif',
		imageBtnClose: 'http://fs.teplotorg.com.ua/images/lightbox/close.gif',
		imageBtnPrev:  'http://fs.teplotorg.com.ua/images/lightbox/prev.gif',
		imageBtnNext:  'http://fs.teplotorg.com.ua/images/lightbox/next.gif',
		txtImage: 'Фотография',
		txtOf: 'из'
   });
	
	//Rotate banners
	/*$('.banners.rotate.one').slides({
		preload: true,
		generateNextPrev: false,
		play: 3000,
	});
	$('.banners.rotate.two').slides({
		preload: true,
		generateNextPrev: false,
		play: 5000,
	});*/

		$('.banners.rotate.one').nivoSlider({
			pauseTime:6000,
			directionNav:false
		});
		$('.banners.rotate.two').nivoSlider({
			controlNav:false,
			controlNavThumbs:false,
			directionNav:false
		});
		$('.banners.left').nivoSlider({
			pauseTime:6000,
			controlNav:false,
			controlNavThumbs:false,
			directionNav:false
		});
		
		/*$(".catalog.fishka ul li").each(function(){
			if($(this).html().search("<td>") < 0){				
				$(this).remove();
			}
		});*/

});
