var oDisplay                  = new Object();
var aOverture                 = new Array();
var sLanguageCode             = new String( window.location ).substr( 7, 2 );

var oPromo       = { adcycle:true, overture:true }; // DEBUG
//var sCountryCode = 'fr';                            // DEBUG


function initPromo( sPromo, sParam_1, sParam_2, sParam_3, sParam_4 ) {

  if (sPromo == 'overture' && oPromo[sPromo]) {
	
	// Pays YSM affichˇs 
	// --------------------------------------------------------------------------------
	
	a_displayableCountries = new Array( 'fr' );
	
	// --------------------------------------------------------------------------------
	
	for(x in a_displayableCountries){
		display_overture = sCountryCode == a_displayableCountries[x] ? true : false;
		break;
	}
	
	// Si pays affichable
	if ( display_overture ){
	
    	var nCategoryID = 0;
    	var nStar       = 0;
    	var sFilter     = '';
    	var sKeyword    = '';
    	var sQuery      = '';

    	if (sParam_1 != null && sParam_2 != null && sParam_3 != null && sParam_4 != null) {

      		nStar    = sParam_1;
      		sFilter  = sParam_2;
      		sKeyword = sParam_3;
      		sQuery   = sParam_4;

    	} else if (sParam_1 != null && sParam_2 != null) {

      		nCategoryID = sParam_1;
      		nStar       = sParam_2;

      		if (sParam_3 != null) { sQuery = sParam_3 }
    	}

    	// var sOrigin = (document.URL.match( /(network_thumb|network|popup_exit_1|popup_exit|popup_1|popup|search)/))[1] || ''; DEBUG
		var sOrigin = 'network';

    	var sSRC    = 'http://overture.wedoo.com/cgi-bin/overture.cgi?' + ((sCountryCode)   ? 'country='    + sCountryCode  + '&' : '')
                                                                    	+ ((nCategoryID)    ? 'categoryid=' + nCategoryID   + '&' : '')
                                                                    	+ ((nStar)          ? 'star='       + nStar         + '&' : '')
                                                                    	+ ((sLanguageCode)  ? 'language='   + sLanguageCode + '&' : '')
                                                                    	+ ((sOrigin)        ? 'origin='     + sOrigin       + '&' : '')
                                                                    	+ ((sFilter  != '') ? 'filter='     + sFilter       + '&' : '')
                                                                    	+ ((sKeyword != '') ? 'keyword='    + sKeyword      + '&' : '')
                                                                    	+ ((sQuery   != '') ?                 sQuery        + '&' : '')
                                                                    	+ Date.parse( new Date() ) + Math.floor( Math.random() * 1000000000 );
     //document.write(sSRC);
    	document.write( '<script language="javascript" src="' + sSRC + '"></scr' + 'ipt>' );
	}
  }
}

function displayPromo( sPromo, sPlaceHolder, sParam ) {

  if (oDisplay[sPlaceHolder] == null && oPromo[sPromo]) {
  //if (oDisplay[sPlaceHolder] == null) {

    if (sPromo == 'adcycle') {

      var nWidth  = parseInt( (sParam.split( 'x' ))[0] );
      var nHeight = parseInt( (sParam.split( 'x' ))[1] );
      var nGID    = parseInt( (sParam.split( 'x' ))[2] );
       
      var oDate   = new Date();
      var sSecond = oDate.getSeconds();
      var sMinute = oDate.getMinutes();
      var sID     = sSecond * sMinute + Math.floor( (Math.random() + 1) * 999 );

      var sURL = 'http://ad.wedoo.com/cgi-bin/adcycle4/adcycle.cgi';

      //  + ((nCategoryID != null) ? nCategoryID : '')
      var sHTML = '<iframe src="' + sURL + '?gid=' + nGID + '&id=' + sID + '&layout=multi&t=_blank&type=iframe&keywords=' + '" width="' + nWidth + '" height="' + nHeight + '" border="0" marginwidth="0" marginheight="0" hspace="0" vspace="0" frameborder="0" scrolling="no">'
                +   '<img src="'  + sURL + '?gid=' + nGID + '&id=' + sID + '&layout=multi&keywords=' + '" width="' + nWidth + '" height="' + nHeight + '" border="1" onclick="window.open(\'' + sURL + '?gid=' + nGID + '&id=' + sID + '&layout=multi\')">'
                + '</iframe>';

      document.write( sHTML );

    } else if (sPromo == 'overture') {

      if (aOverture != null && aOverture.length) {

        if (sParam != null) {

          var sHTML = '';
          for (var i = 0; i < ((sParam == 'search') ? 5 : 3); i++) { if (aOverture.length) { sHTML += aOverture.shift(); } }

          document.write( sHTML );

        } else { if (aOverture.length) { document.write( aOverture.shift() ); } }
      }
    }
	
	}
	
    if (sPlaceHolder != null && sPlaceHolder != '') {	
			oDisplay[sPlaceHolder] = true;
	}

}  


if (!Array.prototype.shift) { 

	Array.prototype.shift = function() {

		firstElement = this[0];
		this.reverse();
		this.length = Math.max( this.length - 1, 0 );
		this.reverse();
		return firstElement;
	}
}
