if ( window.console == undefined || window.console.log == undefined ) {	window.console = { log:function(msg){ /* msg */ } } }
if ( typeof(window.billboard)=="undefined"){ billboard={}; }

billboard.slideshow = new ( function($) {

    var me = this;
	 me.init = function(){
		billboard.broadcaster.addListener( "pageLoaded", function() { me.onPageLoaded(); } );
    };
    me.onPageLoaded = function(){
		if(billboard.section == 'slideshow'){
			document.title = $("#slideshow-title").text();
		
			window.CM8Profile = "content=slideshow-" + $("#slideshow-id").text();
			$("#resizableIframeM1").css('height','250px');
			$("#adMid1").css('height','250px');
			$("#middle1").css('height','250px');
			}
		

		$("#slideshow-wrapper .previous").hide();
		me.sizeSlideshowImages();

		$("#slideshow-wrapper .next").click(function(){
			var $active = $('#image-list IMG.active');
			var $next = $active.next();
			if($next.get(0)){
				$("#slideshow-wrapper #curr-index").text($next.attr("id"));
				me.slideEl(["#image-list IMG",".slideshow-info .caption p",".slideshow-image .credits p"],"next");
				//billboard.ads.refreshAd( $("iframe.ad-iframe.slideshow")[0] );
				billboard.ads.dartAds();
				billboard.metrics.trackPageView();
				me.comscoreBeacon();
			}
			if($next.next().get(0) == undefined) $(this).hide();
			if($next.prev().get(0)) if($("#slideshow-wrapper .previous").is(":hidden")) $("#slideshow-wrapper .previous").show();
		});
		$("#slideshow-wrapper .previous").click(function(){
			var $active = $('#image-list IMG.active');
			var $prev = $active.prev();
			if($prev.get(0)){
				$("#slideshow-wrapper #curr-index").text($prev.attr("id"));
				me.slideEl(["#image-list IMG",".slideshow-info .caption p",".slideshow-image .credits p"],"prev");
				billboard.ads.dartAds();
				//billboard.ads.refreshAd( $("iframe.ad-iframe.slideshow")[0] );
				billboard.metrics.trackPageView();
				me.comscoreBeacon();
			}
			if($prev.prev().get(0) == undefined) $(this).hide();
			if($prev.next().get(0)) if($("#slideshow-wrapper .next").is(":hidden")) $("#slideshow-wrapper .next").show();

		});
	
		$("#close-slideshow").click( function(){
			top.billboard.modal.hide();

		});
		

    };
	me.slideEl = function(arr,dir){
		$(arr).each(function() {
			$(this +".active").addClass("last-active");
			if(dir == 'next') $(this +".active").next().addClass("active");
			else $(this+".active").prev().addClass("active");
			$(this+".last-active").removeClass("active last-active");
		});
		
	};
	me.sizeSlideshowImages = function(){
		lHeight = $('#slideshow-wrapper .slideshow-image').height();
		lWidth = $('#slideshow-wrapper .slideshow-image').width();
		 $("table#image-list img").each( function(o,img){
			 iHeight = $(img).height();
			 iWidth = $(img).width();
			 if(iHeight > iWidth){
				if(iHeight > lHeight) $(img).attr("height", lHeight); 
			 }
			 else{
				if(iWidth > lWidth) $(img).attr("width", lWidth);
			 }
		 });
	 };
	me.comscoreBeacon = function(){
		billboard.log("Comscore.beacon()"); 
		// Begin comScore Tag 
		COMSCORE.beacon({ 
		  c1:2, 
		  c2:7395269, 
		  c3:"", 
		  c4:"", 
		  c5:"", 
		  c6:"", 
		  c15:"" 
		});  
	};
	//On Load
    $( function(){		
        me.init();
	});//End On Load
})(jQuery);

