﻿Carousel = function(){
var getTarget = "http://77.72.25.36:9022/GetAd.ashx";
var clickTarget = "http://77.72.25.36:9022/SetClick.ashx";
var methodType = "GET";
	
	return{
		getGetTarget: function(){
		    return getTarget;
		}
		/**
		 * Enable a zone setting the onclick event in that zone with the passed parameters
		 * @params:
		 * 	cId: The html id attribute of the zone to enable
		 * 	params: 
		 * 		z: the zone identifier
		 * 		adId: the ad identifier
		 */
		,enableZone: function(cId,params)
		{
		    //the swf object steal click event to the dom
		    //this ensure that when the swfobject container obtain the focus (because click happened)
		    //the click is simulated.
		    //on mouseover we attach the event on swf container 
		    $(cId+" > [id^='ox_']").live("mouseover",function(e,name,value){
		        if($(cId+" > [id^='ox_'] > embed")){
		            $(cId+" > [id^='ox_'] > embed").unbind("focus").focus(function(){
		                $(this).click();
		                $(this).unbind("focus");
		            });
		        }
		    });
		    
		    $(cId).click(function()
		    {
                //console.log("dentro click test this:%o",this);
                $(this).trigger("carouselClick");
            });
                       
            $(cId).live("carouselClick",function(e,name,value)
            {
                //console.log("cliccato su e:%o name:%o value:%o",e,name,value);
                
                $.ajax({
		           type: methodType,
		           url: clickTarget,
		           data: "a="+params.adId+"&f="+params.f,
		           dataType:"jsonp",
		           success: function()
		           {
	    	           //console.log("onClick success");
    			   },
				   error:function(a,b,c)
				   {
				        //console.debug(a,b,c);
				   }
		           ,failure:function(msg)
		           {
						//alert("onClick FAILURE "+msg);
				   }
		         });
            });
		}		
	};//eo public area	
}();//eo carousel
