﻿/*Equal heights function, used to make elements the same height*/

(function($) {
	$.fn.equalHeights = function(minHeight, maxHeight) {
		var tallest = (minHeight) ? minHeight : 0;
		function addSize(elem,baseHeight,operation) {
			var border_top = parseInt(elem.css('border-top-width'));
			var border_bottom = parseInt(elem.css('border-bottom-width'));
			var padding_top = parseInt(elem.css('padding-top'));
			var padding_bottom = parseInt(elem.css('padding-bottom'));
			if (operation == 'subtract') {
			if (!isNaN(padding_top)) baseHeight -= padding_top;
			if (!isNaN(padding_bottom)) baseHeight -= padding_bottom;
			if (!isNaN(border_top)) baseHeight -= border_top;
			if (!isNaN(border_bottom)) baseHeight -= border_bottom;
			} else {
			if (!isNaN(padding_top)) baseHeight += padding_top;
			if (!isNaN(padding_bottom)) baseHeight += padding_bottom;
			if (!isNaN(border_top)) baseHeight += border_top;
			if (!isNaN(border_bottom)) baseHeight += border_bottom;
			}
			return baseHeight;
		}
		this.each(function() {
			var height = $(this).height();
			height = addSize($(this),height);
			if (height > tallest) tallest = height;
		});
		if((maxHeight) && tallest > maxHeight) tallest = maxHeight;
			return this.each(function() {
			tallest2 = addSize($(this),tallest,'subtract')
			$(this).height(tallest2);
		});
	};
})(jQuery);


function clientThumbs(){
	var opts1 = jQuery('p.ac span');
	var opts2 = jQuery('.full-logo');
	opts1.bind("mouseenter", function(){
		var position = jQuery(this).position();
		var left = position.left;
		var top = position.top;
		
		jQuery('.full-logo').html(jQuery("span.full-image-size-placeholder", this).html());

		jQuery('.full-logo').css({'top':top-40});
		jQuery('.full-logo').css({'left':left-30});
		jQuery('.full-logo').show();
		
		
	});
	opts2.bind("mouseleave", function(){
		jQuery('.full-logo').hide();
		
	});
};
function featCols() {
	
	jQuery('.feat-columns .feat_item').equalHeights();
	jQuery('.feat_item_body').equalHeights();
	var panelHeight = jQuery('.feat_item').height() * 2 + 15;
	var authorHeight = jQuery('.feat_item').height() -24;
	jQuery('.feat_item_full_height').css({"height":panelHeight});
	jQuery('.feat_item_body .arrow-more').css({"height":panelHeight});
	jQuery('.feat_item_author .padding').css({"height":authorHeight});
	
};
function makeCarousel(){
	jQuery("#homecarousel").jCarouselLite({
    auto: 15000,
    speed: 1000,
    visible: 1,
    btnNext: ".next",
    btnPrev: ".prev"
	});


}
   
      
       function dumpObj(obj, name, indent, depth) {
		 var MAX_DUMP_DEPTH = 100;   
           if (depth > MAX_DUMP_DEPTH) {
                     return indent + name + ": <Maximum Depth Reached>\n";
              }
              if (typeof obj == "object") {
                     var child = null;
                     var output = indent + name + "\n";
                     indent += "\t";
                     for (var item in obj)
                     {
                           try {
                                  child = obj[item];
                           } catch (e) {
                                  child = "<Unable to Evaluate>";
                           }
                           if (typeof child == "object") {
                                  output += dumpObj(child, item, indent, depth + 1);
                           } else {
                                  output += indent + item + ": " + child + "\n";
                           }
                     }
                     return output;
              } else {
                     return obj;
              }
       }
function getNews(){
  $.yql(
    "select * from html where url='http://news.glidetechnologies.com' and xpath='//div[@class=\"article_summary\"]' limit 1",
    function (data) {
			//'<a href="http://news.glidetechnologies.com/'+data.query.results.div.h2.a.href+'">'>data.query.results.div.h2.a.content+'</a>'+data.query.results.div.div.div.p
	      jQuery("#ticker ul li").html('<a href="http://news.glidetechnologies.com'+data.query.results.div.h2.a.href+'">'+data.query.results.div.h2.a.content+'</a> '+data.query.results.div.div.div.p);

	 
//            jQuery('#ticker ul li').html(data.results.div[2].div.h2.content);
        
    }
  );
 };
 function advocates(){
	jQuery('.advocates tr.hidden').hide();
	var opts1 = jQuery('.tab a');
	opts1.bind("click", function(){
		var selectItem = jQuery(this).attr('id');
		jQuery('.advocates td.selected').removeClass('selected');
		jQuery('.advocates tr').hide();
		
		jQuery(this).parent().addClass('selected');
		jQuery('.advocates tr.tabs').show();
		jQuery('.'+selectItem).show();
		return false;
	});
};
if(jQuery('body .ribbonbackground').is(':hidden')){
	featCols();
	if(jQuery('#homecarousel').length > 0){
		makeCarousel();
	
	};
	if(jQuery('.advocates').length > 0){
		advocates();
	}
		
};
function mycarousel_initCallback(carousel)    {
        // Disable autoscrolling if the user clicks the prev or next button.
        carousel.buttonNext.bind('click', function() {
            carousel.startAuto(0);
        });
        carousel.buttonPrev.bind('click', function() {
            carousel.startAuto(0);
        });
        // Pause autoscrolling if the user moves with the cursor over the clip.
        carousel.clip.hover(function() {
            carousel.stopAuto();
        }, function() {
            carousel.startAuto();
        });
    };
this.screenshotPreview = function(){
        /* CONFIG */

                xOffset = 50;
                yOffset = 15;

                // these 2 variable determine popup's distance from the cursor
                // you might want to adjust to get the right result

        /* END CONFIG */
        $("a.screenshot").hover(function(e){
                this.t = this.title;
                this.title = "";
                var c = (this.t != "") ? "" + this.t : "";
                $("body").append("<p id='screenshot'><img src='"+ this.rel +"' alt='url preview' />"+ c +"</p>");
                $("#screenshot")
                        .css("top",(e.pageY - xOffset) + "px")
                        .css("left",(e.pageX + yOffset) + "px")
                        .fadeIn("fast");
    },
        function(){
                this.title = this.t;
                $("#screenshot").remove();
    });
        $("a.screenshot").mousemove(function(e){
                $("#screenshot")
                        .css("top",(e.pageY - xOffset) + "px")
                        .css("left",(e.pageX + yOffset) + "px");
        });
};
this.imagePreview = function(){
        /* CONFIG */

                xOffset = 10;
                yOffset = 30;

                // these 2 variable determine popup's distance from the cursor
                // you might want to adjust to get the right result

        /* END CONFIG */
        $("a.preview").hover(function(e){
                this.t = this.title;
                this.title = "";
                var c = (this.t != "") ? "" + this.t : "";
                $("body").append("<p id='preview'><span>" + c + "</span><img src='" + this.rel + "' alt='Image preview' /></p>");
                $("#preview")
                        .css("top",(e.pageY - xOffset) + "px")
                        .css("left",(e.pageX + yOffset) + "px")
                        .fadeIn("fast");
    },
        function(){
                this.title = this.t;
                $("#preview").remove();
    });
        $("a.preview").mousemove(function(e){
                $("#preview")
                        .css("top",(e.pageY - xOffset) + "px")
                        .css("left",(e.pageX + yOffset) + "px");
        });
};
this.tooltip = function(){
        /* CONFIG */
                xOffset = 10;
                yOffset = 20;
                // these 2 variable determine popup's distance from the cursor
                // you might want to adjust to get the right result
        /* END CONFIG */
        $("a.tooltip").hover(function(e){
                this.t = this.title;
                this.title = "";
                $("body").append("<p id='tooltip'>"+ this.t +"</p>");
                $("#tooltip")
                        .css("top",(e.pageY - xOffset) + "px")
                        .css("left",(e.pageX + yOffset) + "px")
                        .fadeIn("fast");
    },
        function(){
                this.title = this.t;
                $("#tooltip").remove();
    });
        $("a.tooltip").mousemove(function(e){
                $("#tooltip")
                        .css("top",(e.pageY - xOffset) + "px")
                        .css("left",(e.pageX + yOffset) + "px");
        });
};
$(document).ready(function() {
	getNews();
	clientThumbs();
	tooltip();
    imagePreview();
    screenshotPreview();
	if(jQuery('body .ribbonbackground').is(':hidden')){
   	 jQuery('#mycarousel').jcarousel({
	    auto: 2,           
	    visible: 4,
	    scroll:4,
	    wrap: 'circular',
	    initCallback: mycarousel_initCallback
	});
	};
});


