var Product = {
    init: function() {
        this._bindBannerClicks();
    },
    bannerClick: function(banner_element) {
       var button = $(this).find('a.headerButton');
       if (button.length == 0) {
        //check for a link 
       }
    },
    _bindBannerClicks: function() {
        // banner links
        $('a.product_banner_link').each(function() {
            var link = this;
            //find the li and bind a click event to fire the link
            var bannerLi = Product._getBannerLi(link);
            $(bannerLi).css('cursor', 'pointer');

            $(bannerLi).click(function(event) {
               var target_href = $(event.target).attr('href');
               var href = $(link).attr('href');

               // make sure we didn't click on a link
               if (typeof target_href === 'undefined') {
                   s.tl(link, 'o');
                   if(href.match('http') && !href.match('rackspace.com/apps') && !href.match('website.staging')) {
                        window.open(href);
                   } else {
                        window.location = href;
                   }
               }
            });
        }); 
        $('a.product_banner_click_video').each(function() {
            var link = this;

            //find the li and bind a click event to fire the link
            var bannerLi = Product._getBannerLi(link);

            $(bannerLi).css('cursor', 'pointer');
            $(bannerLi).click(function(event) {
                var target_href = $(event.target).attr('href');
                var href = $(link).attr('href');   

                // make sure we didn't click on a link
                if (typeof target_href === 'undefined') {
                    $(link).click();
                }
            });
        }); 
    },
    _getBannerLi: function(element) {
        var banner_parent = $(element).parent('li.product_banner');
        return banner_parent[0];
    }   
}

var faqs = function() {
	$('#content-sub .faqs dd').hide();
	
	$('#content-sub .faqs dt').addClass('expanded').click(function(event) {
		event.preventDefault();
		$(this).toggleClass('expanded');
		$(this).next().toggle();
	});
};

var lightboxes = function() {
	$('.screenshot-list li').each(function(index) {
		$(this).find('.image-group').fancybox({
			'hideOnContentClick': false
		});
	});
};

var videoboxes = function() {
	$('.video_link').fancybox({
		frameHeight: 440,
		frameWidth: 960,
		hideOnContentClick: false
	});
};

var slideShow = function() {
	$('.jquery-cycle').cycle({fx: 'fade', speed: 2500});
};

var whitepaperTracking = function() {
	var iCrossingRedirect = 'http://www.ic-live.com/cr.php?cID=1055&cdid=4927&campID=8&convID=1545&ic_url=';
	var whitepapers = '/osterman_reducing_cost|should_you_outsource|wp_/';
	var $pdfs =  $('.content a[href*=pdf]');
	$pdfs.each(function(){
		if (this.href.match(whitepapers)) this.href = iCrossingRedirect + this.href;
	});
}

$(document).ready(function() {
    Product.init();
	faqs();
	lightboxes();
	videoboxes();
	slideShow();
	whitepaperTracking();
});
