
function TextAreaSelectionHelper(obj) {
  this.target=obj;
  this.target.carretHandler=this; //������ ������ �� ���� ��� ���������� ����

  this.target.onchange=_textareaSaver;
  this.target.onclick=_textareaSaver;
  this.target.onkeyup=_textareaSaver;
  this.target.onfocus=_textareaSaver;
  if(!document.selection) this.target.onSelect=_textareaSaver; //��� �������
  
  this.start=-1;
  this.end=-1;
  this.scroll=-1;
  this.iesel=null; //��� ��
  if (navigator.userAgent.indexOf('IE 8') != -1){
  	this.iesel=1; //��� ��
  }
}
/**
* ������� ����������������� �����
*/
TextAreaSelectionHelper.prototype.getSelectedText=function() {
   return this.iesel? this.iesel.text: (this.start>=0&&this.end>this.start)? this.target.value.substring(this.start,this.end): "";
}
/**
* �������� ��� ��� ��������. ���� ����� �� ��������������(�� ������) � 
* ������� �� �����, �� �������� � ����� ���������� ����.
*
* @argument text String - �������� �������� �� ���� �����
* @argument secondtag String - ���� �����, �� �������� �� ����������, � ����������� ����� ������
*/
TextAreaSelectionHelper.prototype.setSelectedText=function(text) {
  if(this.iesel) {
  	
  	
  	
  	
    if(typeof(secondtag)=="string") {
   		var l=this.iesel.text.length;
      	this.iesel.text=text+this.iesel.text+secondtag;
   		this.iesel.moveEnd("character", -secondtag.length);
    	this.iesel.moveStart("character", -l);   
    } 
    else {
   		this.iesel.text=text;
    }
    this.iesel.select();
  } 
  else{
    this.target.focus();
  	if(this.start>=0&&this.end>=this.start) {
     	var left=this.target.value.substring(0,this.start);
     	var right=this.target.value.substr(this.end);
  		var scont=this.target.value.substring(this.start, this.end);
  		if(typeof(secondtag)=="string") {
    		this.target.value=left+text+scont+secondtag+right;
    		this.end=this.target.selectionEnd=this.start+text.length+scont.length;
    		this.start=this.target.selectionStart=this.start+text.length;    
  		}		 
  		else {  
       		this.target.value=left+text+right;
    		this.end=this.target.selectionEnd=this.start+text.length;
    		this.start=this.target.selectionStart=this.start+text.length;
  		}
  		this.target.scrollTop=this.scroll;
  		this.target.focus();
  } 
  else {  	
    this.target.value+=text + ((typeof(secondtag)=="string")? secondtag: "");
    if(this.scroll>=0) this.target.scrollTop=this.scroll;
  }
}
}
/**
* ��� ������� ��� ���� =)
*/
TextAreaSelectionHelper.prototype.getText=function() {
  return this.target.value;
}
TextAreaSelectionHelper.prototype.setText=function(text) {
  this.target.value=text;
}
/**
* ��������� ��������, ������������ ������� �������
*/
function _textareaSaver() {
  if(document.selection) {
    this.carretHandler.iesel = document.selection.createRange().duplicate();
  } else if(typeof(this.selectionStart)!="undefined") {
    this.carretHandler.start=this.selectionStart;
    this.carretHandler.end=this.selectionEnd;
    this.carretHandler.scroll=this.scrollTop;
  } else {this.carretHandler.start=this.carretHandler.end=-1;}
}






var smiles = [];
	smiles[1] = ':-)';
	smiles[2] = ':-|';
	smiles[3] = ':-@';
	smiles[4] = ':-*';
	smiles[5] = ':-!';
	smiles[6] = ':-(';
	smiles[7] = ';-(';
	smiles[8] = ':-0';
	smiles[9] = ':-P';
	smiles[10] = ':-[]';
	smiles[11] = ';-[';
	smiles[12] = ';-)';
	smiles[13] = '0:-)';
	smiles[14] = ':-{}';
	smiles[15] = ':-{]';
	smiles[16] = '8-)';


	
	
	
function setSmile(el)
{	
	var txtpole = document.getElementById("smiled");	
	var hTextarea = new TextAreaSelectionHelper(txtpole);
	smileID = $(el).attr('class').replace('smile smile_', '');	
	hTextarea.setSelectedText(smiles[smileID]);
	
}

































$(document).ready(function () {

	/********************************************
	*
	* �������� � �����
	*
	********************************************/
	$('.section-carusel ul li .pic').css({"display": "none"});
	$(".pics .new").css({"background-image": "url("+$('.section-carusel li:eq(0) .pic img').attr("src")+")"});
	
	jQuery('.section-carusel ul').jcarousel({
		visible:1,
		scroll: 1,
		auto: 10,
		animation: 300,
		wrap: 'last',
		initCallback: mycarousel_initCallback
	});
	
	
	
	function mycarousel_initCallback(carousel) {
		jQuery('.section-carusel .nav a').bind('click', function() {
			var self = this;
			
			if ($(this).index('.section-carusel .nav a') == 0) {
				itemElement = $('.section-carusel .nav a.active').index(".section-carusel .nav a")  - 1;
				if (itemElement == 0) {
					itemElement = $('.section-carusel .nav a').length-2;
				}
				
			} else if($(this).index('.section-carusel .nav a') == $('.section-carusel .nav a').length-1) {
				itemElement = $('.section-carusel .nav a.active').index(".section-carusel .nav a") + 1;
				if (itemElement == $('.section-carusel .nav a').length-1) {
					itemElement = 1;
				}
			} else {
				itemElement = $(this).text();
			}
			 picElement = itemElement-1;
			
			setTimeout(function () {carousel.scroll(jQuery.jcarousel.intval(itemElement));}, 300);
			return itemElement;
		});
	};
	
	
	/********************************************
	*
	* ����������� ������ 
	*
	********************************************/
	$(".popup").click(function () {
  var self = this;
  var openElement = $(this).attr("class").match(/(\S+)/g);
  for (i=0; i<openElement.length; i++) {
   if (openElement[i] == "safe-position") {
    var safePosition = true;
    break;
   }
  }

  $(".popup-overlay").height($(document).height()).fadeIn(300, function () {
   if(safePosition) {
    $("#"+openElement[openElement.length-1]).css({
     "top":$(self).offset().top,
     "left":$(self).offset().left-$("#"+openElement[openElement.length-1]).width()+63
    });
   } else {

    $("#"+openElement[openElement.length-1]).css({
     "top":($(window).height()/2)-($("#"+openElement[openElement.length-1]).height()/2),
     "left":($(window).width()/2)-($("#"+openElement[openElement.length-1]).width()/2)
    });
   } 
   $("#"+openElement[openElement.length-1]).fadeIn(300);
  });
  return false;
 });
 $(".popupWindow .close, .popup-overlay").click(function () {
  $(".popupWindow").fadeOut(300, function () {
   $(".popup-overlay").fadeOut(300);
  });
 });
	
	/**************************************
	*
	* ���� IE HTML5
	*
	***************************************/
	if (/msie 7.0/.test(navigator.userAgent.toLowerCase())) {
	
		
	}	
	$('#crt').mouseover(function(){
		var divs = $('#crt div');
		for(i=0; i< divs.length;i++){
		$(divs[i]).removeClass('active');
		}
	})
	$('#crt').mouseout(function(){
		var divs = $('#crt div');
		for(i=0; i< divs.length;i++){
			if($(divs[i]).attr('class')=='rating_1' && rating>=1 ){
				$(divs[i]).addClass('active');
			}
			if($(divs[i]).attr('class')=='rating_2' && rating>=2 ){
				$(divs[i]).addClass('active');
			}
			if($(divs[i]).attr('class')=='rating_3' && rating>=3 ){
				$(divs[i]).addClass('active');
			}
			if($(divs[i]).attr('class')=='rating_4' && rating>=4 ){
				$(divs[i]).addClass('active');
			}
			if($(divs[i]).attr('class')=='rating_5' && rating>=5 ){
				$(divs[i]).addClass('active');
			}
		}
		
	})
});

var r = 0;
function setRating(rating){
	if(r==0){
		$.post('/rating.php',{'productID':productID,'userID':userID,'rating':rating},function(data){
				$('#rating').attr('class','rating rating_'+data);
				$('#rating').show();
				$('#crt').hide();
				
		});
		r=1;
	} 
}


function showHoroscope(Hid){
	var id = 'list-window-'+Hid;
	$('.Htext').hide();
	$('#'+id).show();
	
}
