﻿

jQuery(document).ready(function() {

    setActiveHeaderLink();
    getTwitter();


    
    //content height

    var height = 0
    var heightTemp = 0;
    jQuery(".panel").each(function() {
        heightTemp = jQuery(this).height();
        if (heightTemp > 0 && height < heightTemp) {
            height = heightTemp;
        }
    });

//    if (jQuery(".stepcarousel") != null) {
//        height = height + 60;
//        jQuery(".stepcarousel").height(height);
//    }

    jQuery(".stepcarousel").find("div.panel").each(function(index) {
        if (index == 0) {
            var ht = jQuery(this).height() + 60;
            jQuery(".stepcarousel").height(ht);
        }
    });

    if (jQuery.browser.msie) {
        //OnlyCallInIE();
        //  jQuery(".social").pngFix();
    }

    ThreeColumnDisplayEqualHeight();
    setBackToTopPosition();
    //HeaderImage();

    pageScroll();

});



jQuery(window).load(function() {
//set back to top button position
    setBackToTopPosition();

});

function ShowTabToolTip(m, id) {
    var tooltipObj = jQuery('#comment_' + id);
    var tabObj = jQuery("#tab_" + id);
    var offsetTab = tabObj.offset();
    var top = offsetTab.top-75;
    var left = offsetTab.left;

    if (m == 0) {
        if (tabObj.attr("class") != "active") {
            jQuery(tooltipObj).css("top", top).css("left", left);
            jQuery(tooltipObj).show();
        }
    }
    else {
        jQuery(tooltipObj).hide();
    }
}

jQuery(window).load(function() {
//        jQuery('.tweet_list').sideswap({
//            next: '<img src="next.png" />',
//            previous: '<img src="prev.png" />',
//            transition_speed: 100
//        });

//headline_count = jQuery("div.headline").size();

//jQuery("div.headline:eq(" + current_headline + ")").css('top', '5px');

//headline_interval = setInterval(headline_rotate, 5000); //time in milliseconds
//jQuery('.tweet_list').hover(function() {
//    clearInterval(headline_interval);
//}, function() {
//    headline_interval = setInterval(headline_rotate, 5000); //time in milliseconds
//    headline_rotate();
//});

});

var headline_count;
var headline_interval;
var old_headline = 0;
var current_headline = 0;



function getTwitter() {
    jQuery(".tweet").tweet({
        join_text: "auto",
        username: "davewindsor",
        avatar_size: 0,
        count: 20,
        auto_join_text_default: "",
        auto_join_text_ed: "",
        auto_join_text_ing: "",
        auto_join_text_reply: "",
        auto_join_text_url: "",
        loading_text: ""
    });
}

function headline_rotate() {
    current_headline = (old_headline + 1) % headline_count;
    jQuery("div.headline:eq(" + old_headline + ")").animate({ top: -205 }, "slow", function() {
    jQuery(this).css('top', '210px');
    });
    jQuery("div.headline:eq(" + current_headline + ")").show().animate({ top: 0 }, "slow");
    old_headline = current_headline;
    
}

function replaceimgleft(i) {
    if (i == 0)
        document.getElementById('leftimg').src = "images/arrow-left-hover.png";
    else
        document.getElementById('leftimg').src = "images/arrow-left.png";
}

function replaceimgright(i) {
    if (i == 0)
        document.getElementById('rightimg').src = "images/arrow-right-hover.png";
    else
        document.getElementById('rightimg').src = "images/arrow-right.png";
}



function setActiveHeaderLink() {
    var tabMenu=jQuery('.tab-menu');
    if (tabMenu.length > 0) {
        var winHref = window.location.href;
        tabMenu.find("a").each(function() {
            var aHref = jQuery(this).attr("href");
            var index = winHref.indexOf(aHref);
            if (index > 0) {
                jQuery(this).addClass("active");
            }
            else {
                jQuery(this).removeClass("active");
            }
        });
    }
}

function setBackToTopPosition() {

    //back to top position
    var footerRightObj = jQuery(".footer-right").offset();
    var top = footerRightObj.top;
    //jQuery("#spn").text(top);
    var left = footerRightObj.left + 292;
    jQuery(".back-top").css("top", top).css("left", left);
}

function OnlyCallInIE() {
   var height = jQuery(".footer-right").height();
   jQuery(".footer-right").height(height + 3);
}

function ThreeColumnDisplayEqualHeight() {
    equalHeight(jQuery(".three-column"));
}


function HeaderImage() {
    var img = jQuery("#bannerImage"); // Get my img elem
    var pic_real_width, pic_real_height;
    jQuery("<img/>") // Make in memory copy of image to avoid css issues
    .attr("src", img.attr("src"))
    .load(function() {
        pic_real_width = this.width;   // Note: $(this).width() will not
        pic_real_height = this.height; // work for in memory images.
        alert(pic_real_height);
        jQuery(".hero-img").css("height", pic_real_height);
    });
}



function equalHeight(group) {
    var tallest = 0;
    group.each(function() {
    var thisHeight = jQuery(this).height();
        if (thisHeight > tallest) {
            tallest = thisHeight;
        }
    });
    group.height(tallest);
}


function pageScroll() {

    jQuery('.back-top').click(function() {
    var $target = jQuery("#outer");
        $target = $target.length && $target|| $('[name=' + this.hash.slice(1) + ']');
        if ($target.length) {
            var targetOffset = jQuery($target).offset().top;
            jQuery('html,body')
        .animate({ scrollTop: targetOffset }, 1000);
            return false;
        }
    });
}






