 $('.products-list a.price').hover(
  function () {$(this).parent().children("p.image-container").addClass("hover");}, 
  function () {$(this).parent().children("p.image-container").removeClass("hover");}
 );

 $('p.image-container').hover(
  function () {$(this).addClass("hover");}, 
  function () {$(this).removeClass("hover");}
 );
 
 
 //--------------------------------------------------
var to;
var timeout = 3000;
var aspeed = 1000;
var positions = 4;
var current = 0, index = 0, padding = 11;
var active = false;

var expand_comment_form = 'comment_form';

function news_switcher(pos, clicked)
{
	if(!active)
	{
		active = true;
		
		if(clicked)
		{
			clearTimeout(to);
		}
		if(pos > 4 || pos < 0)
		{
			pos = 1;
		}
		var move_to = 0;
		if(pos != 0)
		{
			for(var i = 1; i <= pos; i++)
			{
				move_to += $('#topnews-news li:nth-child('+ i + ')').height();
				move_to += padding;
			}
		}
		else
		{
			move_to = 0;
		}
		$('#topnews-news li').removeClass('active');
		$('#topnews-news li:nth-child('+(pos+1)+')').addClass('active');
		var img_name = $('#topnews-news li.active dd a').attr('rel');
		$('#topnews-image').animate({
			opacity: 0
		}, aspeed/2, function() {
			$('#topnews-image img').attr('src', img_name);
			$('#topnews-image').animate({
				opacity: 1
			}, aspeed/2);
		});
		$('#topnews .marker').animate({
			top: (move_to + 11)
		}, aspeed, function() {
			pos++;
			if(pos > 3)
			{
				pos = 0;
			}
			if(clicked)
			{
				active = false;
				to = setTimeout('news_switcher('+pos+'), false', timeout + aspeed);
				return;
			}
			
			active = false;
			to = setTimeout('news_switcher('+pos+'), false', timeout + aspeed);
		});
	}
} // End news-switcher()


//
// Cookies management:
//

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}
$(document).ready(function () {
	
    var url_link="";
    var align="";
    var br = 1;
    $('#article-text img.zoom-img').each(function(index) {
            
			var width = $(this).width();
            var url_link = $(this).attr("src");
            var align = $(this).attr("align");
            if(align=="left") classDiv = "alignleft";
            else if(align=="right") classDiv = "alignright";
            else if(align!="") classDiv = "aligncenter";
            else classDiv="";
			
            var rel = $(this).attr("rel");
            if(url_link != "")
            {
                tmp = url_link.split("/");
                file = tmp[3];                
                newlink = '/uploads/th640/'+file+'';
                
            }
            $(this).wrapAll('<span class=\"article-image zoom '+classDiv+'\" id="file_'+br+'" ></span>');
            $("#file_"+br+"").append('<a class="lightbox" href="'+newlink+'"><span>увеличете изображението</span></a>');
			br++;
    });

	
	if(current == 0)
	{
		to = setTimeout('news_switcher(1, false)', timeout);
	}
	// -----------------------
	// Comments-form expand:
	// -----------------------
	try {
		if(readCookie(expand_comment_form) == null)
		{
			$('#comment-form').hide();
		}
		else
		{
			$('#comment-form').show();
		}
	} catch(e) {  }
	$('p.addcomment a').click(function() {
		$('#comment-form').slideToggle('slow');
		if(readCookie(expand_comment_form) == null)
		{
			createCookie(expand_comment_form, '1', 7);
		}
		else
		{
			createCookie(expand_comment_form, '0', -1);
		}
		return false;
	});
	
	
 $("#subscribe").submit(function(){
var names = $("#name").val();
var emails = $("#email").val();
$.post("/mailto.php",{"name":names,"email":emails,"action":"1"},function(data){
var res = data.split('|');
if (res[0]==1){
alert(res[1]);
$("#name").val(''); 
$("#email").val(''); }
else alert(res[1]);

})
 });
 	
});

