$(document).ready(function(){

	$("table.prices tr").children("td:first-child").add($("table.prices tr").children("th:first-child")).addClass("first_cel");
    $("table.prices tr").children("td:last-child").add($("table.prices tr").children("th:last-child")).addClass("last_cel");    
    
    // маркировка спеццены
    add_mark2price();
        
    if ($.browser.msie)
    {        
        $("td.bd").html('&nbsp;');
        
        $.each($("table.prices").find("tr").children("td:first-child").add($("tr").children("th:first-child")), 
        function(k,v){
            
            var cel_height = $(v).height();
            if (cel_height%2 != 0) $(v).height(cel_height+1);
        });

        // фикс бага с шириной второй колонки обрамляющей таблицы  
        var parent_table = $("table.twr");
        var ie_coef = 60;
        var ie_width_fix = $("table.twr").width()-ie_coef-20-2-60-130;
        
        $("th#ie_width").css("width", ie_width_fix+"px");
        
        var fixed_width = $("th#ie_width").width();
        //alert(fixed_width);
        if (fixed_width%2 == 0) $("th#ie_width").width(fixed_width+5);         
    }    
    
    $("table.prices tr").not(':first').hover(
		function(){ 
			$(this).children("td").addClass("popular");
			$(this).children("td:first-child").removeClass("first_cel").addClass("pop");
			$(this).children("td:last-child").removeClass("last_cel").addClass("last_cel popEnd");
            $(this).children("td.bd").addClass("fix_bg");

            if ($(this).children("td").length > 0)
            {                              
                $.each($(this).prev("tr").children("td:first-child").add($(this).prev("tr").children("th:first-child")),
                function(k,v){
                
                    var cel_height = $(v).height();
                    var bottom_pos = parseInt($(v).css("padding-bottom"))+1;
                    /*                  
                    if ($.browser.msie)
                    {
                        //if (bottom_pos%2 == 0) bottom_pos = bottom_pos+1;
                    }                
                */
                    $(v).wrapInner("<div class='holder'></div>").find("div.holder").css("height",cel_height+"px").prepend('<img src="/img/green_dot.gif" style="bottom:-'+bottom_pos+'px" class="green_dot" width="'+$(v).parent("tr").parent("tbody").parent("table").width()+'" height="1">');
                
                });                
            }                
		},
		function(){
			$(this).children("td").removeClass("popular");
			$(this).children("td:first-child").removeClass("pop").addClass("first_cel");
			$(this).children("td:last-child").removeClass("popEnd");
            $(this).children("td.bd").removeClass("fix_bg");
            
            $(this).prev("tr").find("img.green_dot").unwrap().remove();
		}
	);

});

$(window).resize(function(){

    if ($.browser.msie)
    {        
        var parent_table = $("table.twr");
        var ie_coef = 60;
        var ie_width_fix = $("table.twr").width()-ie_coef-20-2-60-130;
        
        $("th#ie_width").css("width", ie_width_fix+"px");
        
        var fixed_width = $("th#ie_width").width();
        if (fixed_width%2 != 0) $("th#ie_width").width(fixed_width-1);          
    }
});

function add_mark2price()
{
    //  блямба
    //var market_price_content = $("td.market_price").html();
    $("td.market_price").wrapInner("<div class='mark_wrapper'><div class='mark_holder'></div>").find("div.mark_holder").css("text-shadow","#750d26 1px -1px");
    
    if ($.browser.msie)
    {
        $("td.market_price div.mark_wrapper").find("div.mark_holder").css("color","#750d26").css("padding-left","1px").css("padding-top","24px");
        
        $.each($("td.market_price div.mark_wrapper"), function(k,v){
        
            var market_price_content = $(v).find("div.mark_holder").html();
            $(v).prepend("<div class='shadow_ie'>"+market_price_content+"</div>")            
        });
        
    }
}
