$(function(){
    $('#btn_close_hint').bind('click', function(){
        $('#thint').hide();
        $('#arrow_hint').hide();

    });
    
    $('#btn_close_hint2').bind('click', function(){
        $('#thint2').hide();
        $('#arrow_hint2').hide();

    });
})

function activeTeaser(elm){

    if (elm != null && typeof(elm) != 'undefined')
    {
        elm.src='/media/design/tariffs/pic_teaser_on.gif';
    }
}
function inactiveTeaser(elm){
    if (elm != null && typeof(elm) != 'undefined')
    {
        elm.src='/media/design/tariffs/pic_teaser_off.gif';
    }
}

 $(function()
{
  $(".include img.imghint").click(function(e)
  {
    //debugger;
    var height = $('#arrow_hint').height();
    var leftVal = $(this).offset().left + 4;
    var topVal = $(this).offset().top - height - 2;
    var hint_left = leftVal - ($('#thint').width()/2) + 10;
    var hint_top = topVal - $('#thint').height() - 6;
    $('#arrow_hint').css({left:leftVal,top:topVal}).show();
    $('#thint').css({left:hint_left, top:hint_top}).show();
  });
 });

$(function()
{
    $('.check_cb').bind('click', function(){
        $('.check.checked').toggleClass('checked_cb').toggleClass('unchecked_cb');
        $(this).toggleClass('unchecked_cb').toggleClass('checked_cb');
    });
});



$(function(){
    $('#popupWindow').hide();
    $('#btnClose').bind('click', function(){
        $.unblockUI();
        $('#thint').hide();
        $('#arrow_hint').hide();
    });
    $('.btnMoreid').bind('click', function(){
		$('#thint').hide();
		$('#arrow_hint').hide();
        $.blockUI({
            message: $('#popupWindow')
        });
    });
})
	
function showPacket(id_tariff) {	
	$('#pw_' + id_tariff).find('#btnClose').click(function(){
        $.unblockUI();
        $('#thint2').hide();
        $('#arrow_hint2').hide();
    });
	
    $.blockUI({
        message: $('#pw_' + id_tariff)
    });
}

function showChannelTooltip(source, e, id, name, image, time, lang, site, descr, isTariff) {
	$('#thint2 .title').html(name);
	$('#thint2 .image img').attr('src', image);
	$('#thint2 .time').text(time);
	
	if(lang == '') {
		$('#thint2 .langname').hide();
		$('#thint2 .lang').hide();
		$('#thint2 .brlang').hide();
	}
	else {
		$('#thint2 .lang').text(lang);
		$('#thint2 .langname').show();
		$('#thint2 .lang').show();
		$('#thint2 .brlang').show();
	}
	
	$('#thint2 .site')
		.attr('href', site)
		.text(site);
	
	$('#thint2 .text').html(descr);
	
	
	setTimeout(function() {
		var height_arrow = 11;
		var height_hint = $('#thint2').height();
		var width_border_hint = 0;
		var border_hint = 0;
		var leftVal = 0;
		var topVal = 0;
		
		if(isTariff) {
			leftVal = $(source).offset().left + (source.offsetWidth / 2) - 10;
			topVal = $(source).offset().top - height_arrow;
			
			width_border_hint = $('#border_hint_' + id).width();
			border_hint = $('#border_hint_' + id).offset().left;
			
			bordre_hint_e = e.pageX - border_hint;
			border_hint_part = width_border_hint / 3;
			
			hint_top = topVal - height_arrow - height_hint + 4 + "px";
			hint_left = border_hint - 30 + "px";
			hint_center = border_hint + 175 + "px";
			hint_right = border_hint + 380 + "px";

			$('#arrow_hint2').css({left: leftVal,top: topVal}).show();

			if (bordre_hint_e > 0 && bordre_hint_e < border_hint_part) {
			    $('#thint2').css({left: hint_left, top: hint_top}).show();
			}
			else if (bordre_hint_e >= border_hint_part && bordre_hint_e <= (border_hint_part * 2)) {
			    $('#thint2').css({left: hint_center, top: hint_top}).show();
			}
			else if (bordre_hint_e > (border_hint_part * 2) && bordre_hint_e < (border_hint + width_border_hint)) {
			    $('#thint2').css({left: hint_right, top: hint_top}).show();
			}
			
		}
		else {
			leftVal = $(source).offset().left + (source.offsetWidth / 2) - 10;
			topVal = $(source).offset().top - height_arrow + 4;
			
			width_border_hint = $('#listBlock_' + id).width();
			border_hint = $('#listBlock_' + id).offset().left;
			
			bordre_hint_e = e.pageX - border_hint;
		    border_hint_part = width_border_hint / 2;

		    hint_top = topVal - height_arrow - height_hint + 4 + "px";
		    hint_left = border_hint - 210 + "px";
		    hint_right = border_hint + 175 + "px";

		    $('#arrow_hint2').css({left:leftVal,top:topVal}).show();

		    if (bordre_hint_e > 0 && bordre_hint_e <= border_hint_part) {
		        $('#thint2').css({left: hint_left, top: hint_top}).show();
		    }
		    else if (bordre_hint_e > border_hint_part && bordre_hint_e < (border_hint + width_border_hint)) {
		        $('#thint2').css({left: hint_right, top: hint_top}).show();
		    }
			
		}

    }, 50);
}
