/**
 * @author Cernos(20.10.2008)
 * E-Mail: adm.styland@gmail.com
 * icq: 984-964
 * (http://www.humorland.org)
 */
$(document).ready(function(){  
  $(".main_menu li ul").css({"display":"none"});
   
  $(".main_menu a").each(function(){
	var hreflink = $(this).attr("href");

	if (hreflink.toLowerCase()==location.href.toLowerCase() || location.href.toLowerCase().search(hreflink.toLowerCase())>=0) {
		$("ul",$(this).parents("li")).css({"display":"block"});
		$(this).attr({"class":"active"});
	}
  });
  
    $(".top-menu a").each(function(){
	var hreflink = $(this).attr("href");

	if (hreflink.toLowerCase()==location.href.toLowerCase() || location.href.toLowerCase().search(hreflink.toLowerCase())>=0) {
		$(this).attr({"class":"active"});
	}
  });
  
/*	  if($("#vip-content").attr("id")){
	  	setInterval('$("#vip-content").width($("body").width()-300);',500);
	  }*/

   
  $("#vip,#free").css({"display":"none"});
  
  $("#vip-reg,#free-reg").click(function(){
  	$("#vip-reg,#free-reg").hide(0);
	$("#vip-regsm,#free-regsm").show(0);
	
	if($(this).attr("id").replace("-reg","") == "vip"){$("#"+$(this).attr("id").replace("-reg","-regsm")).css({"background-color": "#fed68b"});}
	else{$("#"+$(this).attr("id").replace("-reg","-regsm")).css({"background-color": "#E6EBEF"});}	
	
	$("#"+$(this).attr("id").replace("-reg","")).show("slow");
  });
  
  $("#vip-regsm,#free-regsm").click(function(){
  	$("#vip,#free").hide(0);
	
	if($(this).attr("id") == "vip-regsm"){$(this).css({"background-color": "#fed68b"});$("#free-regsm").css({"background-color": "white"});}
	else{$(this).css({"background-color": "#E6EBEF"});$("#vip-regsm").css({"background-color": "#FFF9E6"});}
	
	$("#"+$(this).attr("id").replace("-regsm","")).show("slow");
  });
  
   
  /**
   * Case Counter
   */  
   
   //Инициализируем портфель
   if($.cookie("case-count") != null && $.cookie("case-count") != 'NaN' && $.cookie("case-count") != 0){
   		$(".case-count p").html('<a href="/favorites.html" title="Просмотреть список предприятий">'+$.cookie("case-count")+"</a>");
   }
   
   //Добавление записи в портфель
   $(".add-case, .delete-case").click(function(){		
		if ($(this).attr('class') == 'add-case') {
			if($.browser.msie && $.browser.version < 7){
				alert("Эта опция доступна для Internet Explorer 7 и выше."); return false;
			}
			
			if ($.cookie('case-company') == null){
				$.cookie('case-company', '|' + $(this).attr('id').replace('company-', ''),{path:'/'});
				$.cookie("case-count", '01',{path:'/',expires: 7});
			}
			else {
				$.cookie('case-company', $.cookie('case-company') + '|' + $(this).attr('id').replace('company-', ''),{path:'/',expires: 7});
				//if (parseInt($.cookie("case-count")) < 10) {alert(parseInt($.cookie("case-count").replace('0','')));
					$.cookie("case-count", '0' + (parseInt($.cookie("case-count").replace('0','')) + 1), {
						path: '/',
						expires: 7
					});
				/*}
				else {alert('hight');
					$.cookie("case-count", (parseInt($.cookie("case-count")) + 1), {
						path: '/',
						expires: 7
					});
				}*/
			}
			
			$(".case-count p").html('<a href="/favorites.html" title="Просмотреть список предприятий">' + $.cookie("case-count") + "</a>");
			
			$(this).attr({
				'class': 'delete-case'
			});			
			$('img', this).attr({
				'src': $('img', this).attr('src').replace('add', 'delete')
			});			
		}else{
			if($.cookie("case-count")< 10 )
					$.cookie("case-count", '0'+(parseInt($.cookie("case-count")) - 1),{path:'/',expires: 7});
				else
					$.cookie("case-count", (parseInt($.cookie("case-count")) - 1),{path:'/',expires: 7});
			if($.cookie("case-count") == 0)
				$(".case-count p").html('0');
			else
				$(".case-count p").html('<a href="/favorites.html" title="Просмотреть список предприятий">' + $.cookie("case-count") + "</a>");
			
			$.cookie('case-company', $.cookie('case-company').replace('|' + $(this).attr('id').replace('company-', ''),''),{path:'/',expires: 7})
			
			$(this).attr({
				'class': 'add-case'
			});
			$('img', this).attr({
				'src': $('img', this).attr('src').replace('delete', 'add')
			});
		}
		return false;
   });
   
   //Удаление всех записей
   $('.case-clear').click(function(){
   		$.cookie('case-count',null,{path:'/',expires: 7});
		$.cookie('case-company',null,{path:'/',expires: 7});
		$(".case-count p").html('0');		
		$(".delete-case img").attr({"src":$(".delete-case img").attr("src").replace('delete','add')});
		$(".delete-case").attr({"class": "add-case"});
		
		return false;
   });
   
	
});
