function typeSelect() {
	if(!$(this).hasClass('selected')) {
		var target = $(this).attr('rel');
		$("#type-select a.selected").removeClass('selected');
		$(this).addClass('selected');
		$('.tab').toggleClass('active');
		return false;
	} else {
		return false;
	}
}
$(function(){
	$("#type-select a").bind("click", typeSelect);
	
	$.each($("li.sizes"), function(i, val){
        $.fn.qtip.styles.mystyle = { 
           width: 200,
           background: '#f7f3e8',
           color: 'black',
           textAlign: 'left',
		   borderStyle: 'dotted',
		   'list-style': 'none',
		   padding: '8px',
           border: {
              width: 1,
              radius: 1,
              color: '#000'		  
           },
           name: 'light'
        }

        var theContent = $(val).children('div').html();
		if(theContent == null) 
		{
			return true;
		}
		$(val).qtip({
				content: theContent,
				position: {
						  corner: {
							 target: 'bottomLeft'
						  },
						  adjust: { y: -18 }
					   },
				hide: {
					  fixed: true,
					  delay: 240
					},
				style: 'mystyle'
			});
    });
});

function readCookie(name)   
{
  var xname = name + "=";
  var xlen = xname.length;
  var clen = document.cookie.length;
  var i = 0;
  while(i < clen)
  {
    var  j = i + xlen;
    if (document.cookie.substring(i, j) == xname) 
      return  getCookieVal(j);
    i = document .cookie. indexOf(" ",i) + 1;
    if (i == 0) break;
  }
  return  null;
}
// Вспомогательная  функция, вызываемая  из readCookie()
function  getCookieVal(n)
{
  var  endstr  =  document.cookie.indexOf(";", n);
  if (endstr == -1)
    endstr = document.cookie.length;
  return unescape(document.cookie.substring(n,endstr));
}
 
//Запись  cookie
function writeCookie(name,value,expires,path,domain,secure)
{
	var d1 = new Date();
	var d2 = d1.getTime() + (365*24*60*60*1000);
	d1.setTime(d2);
	expires = d1;
	document.cookie = name + "=" + escape(value) +
	((expires)  ?  "; expires=" + expires.toGMTString():   "") + 
	((path)  ?  "; path=" + path   :   "")   + 
	((domain)  ?  "; domain="   +  domain :   "")   + 
	((secure)  ?  ";   secure"  :   "");
}
