jQuery(document).ready(function() {
    jQuery('#small_items_topnews div.top_news_item').mouseover(function(){
        // clone
        var bigItem = jQuery(this).clone(true).attr({id: 'big_item'}).css({height: '100%'});
        bigItem.unbind('mouseover');
        // layout corrections
        jQuery('img.play_image', bigItem).remove();
        jQuery('img.small_image', bigItem).parent().after(jQuery('.h3', bigItem).parent().remove());
        jQuery('div.intro_bottom_text:not(:has(input[type=button]))', bigItem).remove();
        jQuery('div.intro_bottom_text:has(input[type=button])', bigItem).css({width: '100%', textAlign: 'right'});
        // append
        jQuery('#big_item_topnews').empty().append(bigItem);
        // truncate intro
        var maxTries = 1000;
        while ((jQuery('#big_item').height() > jQuery('#small_items_topnews').height()) && (maxTries-- > 0))
            jQuery('#big_item p.intro').text(jQuery('#big_item p.intro').text().replace(/\W*\w+\W*\.*\s*$/, '...'));
        // set button
        jQuery('.top_news_item_active').removeClass('top_news_item_active').addClass('top_news_item_inactive').children('.background_top_news_item').hide();
        jQuery(this).parents('.top_news_item_inactive').addClass('top_news_item_active').children('.background_top_news_item').css({height: jQuery(this).parents('.top_news_item_white_border').height()}).show();
        // fix height
        jQuery('.top_news_item_active .background_top_news_item img').height(jQuery('.top_news_item_active').height());
    });
    jQuery('div.top_news_item:first').trigger('mouseover');
    // button hover init
    jQuery('div.top_news_item:first').trigger('mouseover');
    // video play button
    jQuery('#small_items_topnews div.top_news_item_video img.small_image').load(function(){
        var image = jQuery(this);
        if (image.parents('#big_item').size()) {
            var width = 44;
            image.before('<img class="play_image" src="/img/common/video_rectangle_large.gif" /'+'>');
            image.prev().css({position:'absolute', zIndex:1, width:width+'px', opacity:0.6});
        }
    });
});
jQuery(window).load(function(){ 
	jQuery(window).load(function() {
	   jQuery('div#small_items_topnews div.top_news_item_inactive:last-child > div').css('height', jQuery('div#small_items_topnews div.top_news_item_inactive:last-child').height()); 
	});
});

