// redefine Cycle's updateActivePagerLink function
//    $.fn.cycle.updateActivePagerLink = function (pager, currSlideIndex) {
//        $(pager).find('li').removeClass('activeSlide').filter('li:eq(' + currSlideIndex + ')').addClass('activeSlide').animate({left: '10px'},'slow');
//    }
function image_resize() {
    $(".main_image img").each(function () {
        /* Max width for the image */
        var maxWidth = 400;
        /* Max hieght for the image */
        var maxHeight = 235;
        /*Used for aspect ratio*/
        var ratio = 0;
        /*Current image width*/
        var width = $(this).width();
        /*Current image height */
        var height = $(this).height();

        /*Check if the current width is larger than the max*/
        if (width > maxWidth) {
            /*get ratio for scaling image*/
            ratio = (maxWidth / width);
            /* Set New hieght and width of Image*/
            $(this).attr({
                width: maxWidth,
                height: (height * ratio),
                alt: "your-alt-text-you-can-remove-this"
            });
            /* Reset height to match scaled image */
            height = (height * ratio);
            /* Reset width to match scaled image */
            width = (width * ratio);
            /*Check if current height is larger than max*/
            if (height > maxHeight) {
                /*get ratio for scaling image*/
                ratio = (maxHeight / height);
                /*Set new height and width*/
                $(this).attr({
                    height: maxHeight,
                    width: (width * ratio),
                    alt: "your-alt-text-you-can-remove-this"
                });

            }
        }
    });
}

$(document).ready(function () {
    if (jQuery('#slides').children().size() > 0) {
        jQuery('#sliderholder').css('display', 'block');
        jQuery('#sliderholder').css('z-index', '-10000');
        jQuery('#slides').css('z-index', '1');
        jQuery('#slides').children('.main_image').removeClass('static');
        jQuery(".main_image .block").animate({ opacity: 0.82 }, 1);
        jQuery('#pause').css('display', 'block');

        if (jQuery(window).width() < 1300) {

            $('h3.twitter').addClass('twitterwide');
            $('img.twitter').addClass('twitterwide');
        } else {
            $('h3.twitter').removeClass('twitterwide');
            $('img.twitter').removeClass('twitterwide');
        }

        if (jQuery(window).width() < 990) {
            jQuery('#sliderholder').addClass('min');
        } else {
            //$('#tabs').find('a').not('img').text('');
            jQuery('#sliderholder').removeClass('min');
        }

    }

    jQuery('#pause').click(function () {
        jQuery('#slides').cycle('toggle');

        var text = $('#pause').text();
        $('#pause').text(
        text == "Pause" ? "Resume" : "Pause");

    });


    jQuery('#slides').cycle({
        fx: 'scrollLeft',
        timeout: 7000,
        speed: 800,
        easing: 'easeInOutCirc',
        pause: 1,
        pager: '#tabs',
        updateActivePagerLink: null,
        pagerAnchorBuilder: function (idx, slide) {
            var x = idx;
            var linkText = jQuery(slide).find("h3").text()
            if (jQuery('#slides').children().size() > 1) {
                var imgSrc = jQuery(slide).find("img").attr("src")
                var imgSplit = imgSrc.split("newsSlider/");
                var sml_img = imgSplit[0] + "newsSlider/sml/" + imgSplit[1];
                //return '<li><a href="#"><img src="' + slide.src + '" width="35" height="35" />' + jQuery(slide).text() + '</a></li>';
                //return '<li>' + jQuery(slide).children("h3").eq(0).text() + '<p>' + jQuery(slide).children("p").eq(0).text() + '</p></li>';
                return '<a href="javascript:void(0)" title="' + linkText + ' - further information."><img src="' + sml_img + '" width="70" height="50" alt="' + linkText + '"/></a>';
            }
        }
    });

});

jQuery(window).resize(function () {
    
      if (jQuery(window).width() < 1300) {

        $('h3.twitter').addClass('twitterwide');
        $('img.twitter').addClass('twitterwide');
    } else {
    $('h3.twitter').removeClass('twitterwide');
    $('img.twitter').removeClass('twitterwide');
    }
    
       
        if (jQuery(window).width() < 990) {
            jQuery('#sliderholder').css('width','100%');
            jQuery('#sliderholder').css('overflow','hidden');
        } else {
            //$('#tabs').find('a').not('img').text('');
            jQuery('#sliderholder').css('width','400px');
        }


});
