/* Haberler Slider Başlar */

$(function () {
    otomatikBoyutlandir();
    //Show Banner
    haberSec($(".HaberSagAlan ul li:first"));
    $(".HaberSolResim .HaberAltAciklama").show(); //Show Banner
    $(".HaberSolResim .block").animate({ opacity: 0.85 }, 1); //Set Opacity


    //Click and Hover events for thumbnail list
    $(".HaberSagAlan ul li a").click(function (e) { e.preventDefault(); });
    $(".HaberSagAlan ul li").click(function (e) {
        if ($(this).attr('class').indexOf('see-all') == -1) {
            e.preventDefault();
            haberSec($(this));
        } else {
            window.location = $(this).find("a").attr('href');
        }
    }).hover(function () {
        $(this).addClass('hover');
    }, function () {
        $(this).removeClass('hover');
    });
});    //Close Function


function haberSec(li) {
    var nopic = false;
    var imgAlt = li.find('img').attr("alt"); //Get Alt Tag of Image
    var imgUrl = li.find('a').attr("href"); //Get Main Image URL
    var imgDesc = li.find('.block').html(); 	//Get HTML of block
    var imgDescHeight = $(".HaberSolResim").find('.block').height(); //Calculate height of block
    var imgTitle = li.find('h2 a').text();
	while(imgTitle[imgTitle.length-1] ==' '){ imgTitle = imgTitle.substr(0, imgTitle.length-2); }
    var url = li.find('h2 a').attr("href");

    if (imgUrl == '') {
        imgUrl = '/app/theme/images/no-new-pic.png';
        nopic = true;
    }


    if (li.is(".active")) {  //If it's already active, then...

    } else {
        //Animate the Teaser		
        $(".HaberSolResim")
        $(".HaberSolResim .block").animate({ opacity: 0, marginBottom: -imgDescHeight }, 250, function () {
            $(".HaberSolResim .block").html(imgDesc).animate({ opacity: 0.85, marginBottom: "0" }, 250);
            if (nopic) {
                $(".HaberSolResim img").attr({ src: '/content/images/spacer.gif', alt: imgAlt, title: imgTitle }).css('background', 'url(' + imgUrl + ') no-repeat center center');
            } else {
                $(".HaberSolResim img").attr({ src: imgUrl, alt: imgAlt, title: imgTitle });
            }
            
            $(".HaberSolResim img").parent('a').attr('href', url);
        });
        li.addClass('selected');
    }

    $(".HaberSagAlan ul li").removeClass('selected'); //Remove class of 'active' on all lists
    li.addClass('selected');  //add class of 'active' on this list only
}

/* Haberler Slider Biter */

function otomatikBoyutlandir() {
    var solSutun = $("#SolSutun");
    var ortaSutun = $("#OrtaSutun");
    var sagSutun = $("#SagSutun");

    var solSutunYukseklik = solSutun.outerHeight(true);
    var ortaSutunYukseklik = ortaSutun.outerHeight(true) - 15;
    var sagSutunYukseklik = sagSutun.outerHeight(true);

    var commonHeight = solSutunYukseklik;
    if (ortaSutunYukseklik > commonHeight) {
        commonHeight = ortaSutunYukseklik;
    }
    if (sagSutunYukseklik > commonHeight) {
        commonHeight = sagSutunYukseklik;
    }

    solSutun.height(commonHeight);
    ortaSutun.height(commonHeight);
    sagSutun.height(commonHeight);
}

