function AlertSubmit()
{
	document.getElementById("shadowedAlert").style.display="none";
	document.getElementById("zoomLayer").style.display="none";
}

function getElementsByClass(searchClass,node,tag) 
	{
		var classElements = new Array();
		if ( node == null )	node = document;
		if ( tag == null ) tag = '*';
		var els = node.getElementsByTagName(tag);
		var elsLen = els.length;
		
		var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
		for (i = 0, j = 0; i < elsLen; i++) 
		{
			if ( pattern.test(els[i].className) ) 
			{
				classElements[j] = els[i];
				j++;
			}
		}
		return classElements;
	}

function block_open(id)
{
	var block = document.getElementById('block_'+id).style.display;
	
	if(block == 'none')
	{
		var obj = getElementsByClass('menu_block',null,'div');
		for(i=0;i<obj.length;i++)
		{
			if(obj[i].style.visibility != 'visible')
			{
				obj[i].style.display = 'none';
			}
		}
		
		document.getElementById('block_'+id).style.display = 'block';
	}
	else
	{
		document.getElementById('block_'+id).style.display = 'none';
	}
}

function bla()
{
	document.write='sdfds';
}

function changeStar(star, id)
{
	document.getElementById(id).src=star;
}

function setblockposition() {
	var wi = $(window).width();
	var freeWi = wi - 335;
	if (freeWi > 1000) {
		$(".l_header .ll").width(1000);
		$(".l_header .ll").css("float", "right");
	} else {
		$(".l_header .ll").width(freeWi);
		$(".l_header .ll").css("float", "right");
	}
}

$(document).ready(function()
{
	$('html,body').animate({scrollTop: "0px"}, 500);
	if ($.browser.msie) {
		setblockposition();
		$(window).bind("resize", setblockposition);
	}
	
	if($('.imgs').find('img').size()==0)
	{
		$('a.imgs').hide();
	}
	
	$('a.imgs').click(function(){
		$(this).parents("div:first").children("a.active").removeClass("active");
		$(this).addClass("active");
		
		$('div.imgs').show('slow');
		$('div.chs').hide('slow');
		$('div.comment').hide('slow');
		
		
	})
	
	$('a.chs').click(function(){
		$(this).parents("div:first").children("a.active").removeClass("active");
		$(this).addClass("active");	
		
		$('div.imgs').hide('slow');
		$('div.chs').show('slow');
		$('div.comment').hide('slow');

	})	
	
	$('a.cmts').click(function(){
		$(this).parents("div:first").children("a.active").removeClass("active");
		$(this).addClass("active");	
		
		$('div.imgs').hide('slow');
		$('div.chs').hide('slow');
		$('div.comment').show('slow');
	})
	
	
	
	
	$('.fblur').focus(function(){
		if($(this).val()==$(this).attr('rel'))
		{
			$(this).val('');
			$(this).addClass('activeTextField');
		}
	});
	
	$('.fblur').blur(function(){
		if($(this).val()=='')
		{
			$(this).val($(this).attr('rel'));
			$(this).removeClass('activeTextField');
		}
	});
	
	$('.myform').submit(function()
	{			
		$(this).ajaxSubmit(
		{
			target: "#nice",
			type: 'POST',
			timeout: 7000,
			beforeSend: function () 
			{
				$('html').append('<div id="load"><span class="loading"></span></div>');
				$('#load').animate({ opacity: "0.8" }, 300);
			},
			complete: function () 
			{
				$('#load').remove();
			}
		});
		return false;
	});
});

$(document).ready(function()
{
	$('a.ajax').click(function()
	{
		getRequest(this);
		return false;
	});
});

function getRequest(at)
{
	var uri = $(at).attr('href');

	if(uri != '#')
	{
		$.ajax(
		{
			url: uri,
			type: 'GET',
			timeout: 7000,
			beforeSend: function (){
				$(at).next('img.cartload').fadeIn();
			},
			complete: function () {
				$(at).next('img.cartload').fadeOut(function() {
					if($(this).next('span.added').size() == 0)
					{
						$(this).after('<span class="added">товар добавлен в корзину</span>');
					}
				})
				
				
			},
			success: function (data)
			{
				$('#cardout').html(data);
			},
			error: function(){
				alert('Ошибка сервера! Повторите еще раз!');
			}
		});
	}
	else
	{
		return false;
	}
}

$(document).ready(function()
{
	$.preloadImages = function()
	{
	  for(var i = 0; i<arguments.length; i++)
	  {
	    jQuery("<img>").attr("src", arguments[i]);
	  }
	}
});

$(document).ready(function()
{
	$('img.offset').mousemove(function(event)
	{
		var leftPos = parseInt($(this).css('left'));
		var rightPos = parseInt($(this).css('width'));
		
		startPoint = event.pageX;
		
		var bg = event.pageX-$(this).offset().left;
		bg = bg/5;
		
		rate = 0;
		if(bg<4) {rate = 1;}
		else if(bg<8) {rate = 2;}
		else if(bg<12){rate = 3;}
		else if(bg<16) {rate = 4;}
		else if(bg<20) {rate = 5;}
		
		for(i=0; i<=5; i++)
		{
			$.preloadImages('http://kernel.dimax.in.ua/images/rating/rating_'+i+'.png');
		}
		
		$(this).attr('src', 'http://kernel.dimax.in.ua/images/rating/rating_'+rate+'.png');
		$(this).attr('rel', rate);
	});
	return false;
});

function setrate(module, item)
{	
		if(confirm('Голосуем ?')) 
		{
			var uri = 'module-'+module+'-item-'+item;
			
			$.ajax(
			{
				url: uri+'-rate-'+$('#'+item).attr('rel'),
				type: 'GET',
				timeout: 7000,
				success: function (data)
				{
					$('#'+item).attr('src', 'http://kernel.dimax.in.ua/images/rating/rating_'+data+'.png');
				}
			});	
			return false;
		}
}

$(document).ready(function()
{
    $('#wysiwyg').wysiwyg({
		controls : {    
		separator04 : { visible : false },
        insertOrderedList : { visible : false },
        insertUnorderedList : { visible : false },
		strikeThrough : { visible : true },
		underline : { visible : true },
		separator00 : { visible : true },
		justifyLeft : { visible : true },
		justifyCenter : { visible : true },
		justifyRight : { visible : true },
		justifyFull : { visible : true },
		separator01 : { visible : false },
		createLink :  { visible : false },
		insertImage : {visible   : true},
		separator08 : { visible : false },
		indent : { visible : false },
		outdent : { visible : false },
		separator02 : { visible : false },
		h1 : { visible : false },
		h2 : { visible : false },
		h3 : { visible : false },
		h1mozilla : { visible : false },
		h2mozilla : { visible : false },
		h3mozilla : { visible : false },
		subscript : { visible : false },
		superscript : { visible : false },
		separator03 : { visible : false },
		undo : { visible : false },
		redo : { visible : false },
		insertHorizontalRule : { visible : false },
		separator05 : 	{ visible : true },
		increaseFontSize : { visible : true },
		decreaseFontSize : { visible : true },
		separator09 : { visible : false },
		removeFormat : { visible : false }
		}
	});
});

$(document).ready(function()
{
	$('#commentadd').click(function()
	{
		$('#commentadding').slideToggle("slow");
	});
	return false;
});

$.cookie = function(name, value, options) {
    if (typeof value != 'undefined') {
        options = options || {};
        if (value === null) {
            value = '';
            options = $.extend({}, options);
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString();
        }

        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else {
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = $.trim(cookies[i]);
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};

$(document).ready(function()
{
	var gp = $.cookie("screen_pos");
	window.scrollTo(50, gp);

	$(window).unload(function () { 
		var p = $(window).scrollTop();	   
		$.cookie("screen_pos", p);
	});
});