////////////////////////////////////////////////////////////////////////////////
// slider
////////////////////////////////////////////////////////////////////////////////
jQuery(window).bind("load", function() {
	jQuery(".csw").codaSlider()
});
////////////////////////////////////////////////////////////////////////////////
$(function() {
////////////////////////////////////////////////////////////////////////////////
// load default API
////////////////////////////////////////////////////////////////////////////////
	$('#integrate form')[ 0 ].reset();
	$('#integrate .column2 form')[ 0 ].reset();
	$('.gallery-colors').hide();
	$('.banner-colors').hide();
	$('.console-radio').attr("checked","checked");
	$('#integrate .start input').click(function() {
		var
		value=$(this).attr('value');
		// auto pop. the iframe and code with default
		$('#integrate .default-iframe').hide(0);
		$('#integrate .column2 form')[ 0 ].reset();
		$('#edit-theme').hide();
		if (value=="#list") {
			$('#integrate .form-container').empty(0).load('/marketing/filters/list');
			$('#integrate .column1 code').empty(0).append('&lt;iframe src="http://'+window.location.hostname+'/console/api/mapNr-0_layout-L4_f-aboveL'+URIaffID+'" width="700px" height="530px" frameborder="0" scrolling="no"&gt;&lt;/iframe&gt;');
			$('#integrate .column1 .iframe').empty(0).append('<iframe src="http://'+window.location.hostname+'/console/api/mapNr-0_layout-L4_f-aboveL'+URIaffID+'" width="700px" height="530px" frameborder="0" scrolling="no"></iframe>').show();
			$('#edit-theme-advanced div').show();
			$('.map-colors').hide();
			$('.gallery-colors').hide();
			$('.banner-colors').hide();
		} else if (value=="#map") {
		$('.form-container').empty(0).load('/marketing/filters/map');
			$('#integrate .column1 code').empty(0).append('&lt;iframe src="http://'+window.location.hostname+'/console/api/listNr-0'+URIaffID+'" width="700px" height="530px" frameborder="0" scrolling="no"&gt;&lt;/iframe&gt;');
			$('#integrate .column1 .iframe').empty(0).append('<iframe src="http://'+window.location.hostname+'/console/api/listNr-0'+URIaffID+'" width="700px" height="530px" frameborder="0" scrolling="no"></iframe>').show();
			$('#edit-theme-advanced div').show();
			$('.list-colors').hide();
			$('.gallery-colors').hide();
			$('.banner-colors').hide();
		} else if (value=="#banner") {
			$('#integrate .form-container').empty(0).load('/marketing/filters/banner');
			$('#integrate .column1 code').empty(0).append('&lt;iframe src="http://'+window.location.hostname+'/console/api/listNr-5_layout-L7_size-250x250_venue-tap_oClosest-1'+URIaffID+'" width="250px" height="250px" frameborder="0" scrolling="no"&gt;&lt;/iframe&gt;');
			$('#integrate .column1 .iframe').empty(0).append('<iframe src="http://'+window.location.hostname+'/console/api/listNr-5_layout-L7_size-250x250_venue-tap_oClosest-1'+URIaffID+'" width="250px" height="250px" frameborder="0" scrolling="no"></iframe>').show();
			$('#edit-theme-advanced div').show();
			$('.header-colors').hide();
			$('.menu-colors').hide();
			$('.filter-colors').hide();
			$('.map-colors').hide();
			$('.list-colors').hide();
			$('.gallery-colors').hide();
			$('.footer-colors').hide();
		} else if (value=="#datafeeds") {
			$('#integrate .form-container').empty(0).load('/marketing/datafeeds');
			$('#integrate .column1 code').empty(0).append('JSON FEED @ http://'+window.location.hostname+'/console/api/output-json_mapNr-0'+URIaffID);
			$('#integrate .column1 .iframe').empty(0).append('<iframe src="http://'+window.location.hostname+'/console/api/output-json_mapNr-0_preview-1'+URIaffID+'" width="700px" height="530px" frameborder="0" scrolling="yes"></iframe>').show();
			$('#edit-theme-advanced div').show();
			$('.header-colors').hide();
			$('.menu-colors').hide();
			$('.filter-colors').hide();
			$('.map-colors').hide();
			$('.list-colors').hide();
			$('.gallery-colors').hide();
			$('.footer-colors').hide();
		} else if (value=="#console") {
			$('#integrate .form-container').empty(0).load('/marketing/filters/console');
			$('#integrate .column1 code').empty(0).append('&lt;iframe src="http://'+window.location.hostname+'/console/api/'+URIaffID+'" width="700px" height="530px" frameborder="0" scrolling="no"&gt;&lt;/iframe&gt;');
			$('#integrate .column1 .iframe').empty(0).append('<iframe src="http://'+window.location.hostname+'/console/api/'+URIaffID+'" width="700px" height="530px" frameborder="0" scrolling="no"></iframe>').show();
			$('#edit-theme-advanced div').show();
			$('.gallery-colors').hide();
			$('.banner-colors').hide();
		}
	});
////////////////////////////////////////////////////////////////////////////////
// load user generated API
////////////////////////////////////////////////////////////////////////////////	
	$('#integrate .form-container button').live('click', function() {
    // sets default colors
		set_defaults();
    var	height;
    // identifies form
		var id=$(this).parent().parent().attr('id');
		// gets the basic form values
		custparam='';
    width=$("select[name='size']").val();
	
    if(width!="700" && width!==undefined ){custparam=custparam+'_size-'+width;}
		mapNr=$('.mapNr input').attr('value');

    if(mapNr!="50" && mapNr!==undefined){custparam=custparam+'_mapNr-'+mapNr;}
		listNr=$('.listNr input').attr('value');

    if(listNr!="20" && listNr!==undefined){custparam=custparam+'_listNr-'+listNr;}
		venue=$("select[name='venue']").val();

    if(venue!=="" && venue!==undefined){custparam=custparam+'_venue-'+venue;}
		f=$("select[name='f']").val();

		if(f!=="" && f!==undefined){custparam=custparam+'_f-'+f;}
		layout=$("select[name='layout']").val();

		if(layout!=="" && layout!==undefined){custparam=custparam+'_layout-'+layout;}	
		dist=$("select[name='dist']").val();
		if(dist!=="" && dist!==undefined){custparam=custparam+'_dist-'+dist;}

		recent=$("select[name='recent']").val();
		if(recent!=="" && recent!==undefined){custparam=custparam+'_recent-'+recent;}
		Lscroll=$("select[name='Lscroll']").val();
		if(Lscroll!=="" && Lscroll!==undefined){custparam=custparam+'_Lscroll-'+Lscroll;}
		bb=$("select[name='bb']").val();
		if(bb!=="" && bb!==undefined){custparam=custparam+'_bb-'+bb;}
		// gets the advanced filter form values
		fTown=$("select[name='fTown']").val();

		if(fTown!==undefined && fTown!==""){custparam=custparam+'_fTown-'+fTown;} 
    if($("input[name=fAct]").val()!="any" && $("input[name=fAct]").val()!="" && $("input[name=fAct]").val()!=undefined && $("select#actFilt").val()!='0'){
      custparam=custparam+'_'+$("select#actFilt").val()+'-'+($("input[name=fAct]").val()).replace(/,/g,'--');
    }
    if($("select#actFilt").val()=="0"){custparam=custparam+'_fAct-0';}
    fClosest=$("select[name='fClosest']").val();
		if(fClosest!=="" && fClosest!==undefined){custparam=custparam+'_fClosest-'+fClosest;}
    fAdv=$("select[name='fAdv']").val();
		if(fAdv!=="" && fAdv!==undefined){custparam=custparam+'_fAdv-'+fAdv;}
		fAge=$("select[name='fAge']").val();
		if(fAge!=="" && fAge!==undefined){custparam=custparam+'_fAge-'+fAge;}	
		fBudget=$("select[name='fBudget']").val();
		if(fBudget!=="" && fBudget!==undefined){custparam=custparam+'_fBudget-'+fBudget;}
		// gets the advanced onload form values
		oTown=$('#townsearch').val();
		if(oTown!=="" && oTown!==undefined){custparam=custparam+'_oTown-'+lookupTown();}
		oVenue=$("select[name='oVenue']").val();
		if(oVenue!=="" && oVenue!==undefined){
      custparam=custparam+'_oVenue-'+oVenue;
      custparam= custparam.replace('oVenue-oVenue','oVenue');
    }
		oVenAct=$("select[name='oVenAct']").val();
    if(oVenAct!=="" && oVenAct!==undefined){custparam=custparam+'_oVenAct-'+oVenAct;}
    if($("input[name=oAct]").val()!="any" && $("input[name=oAct]").val()!="" && $("input[name=oAct]").val()!=undefined){
      custparam=custparam+'_'+$("select#actOpen").val()+'-'+($("input[name=oAct]").val()).replace(/,/g,'--');
    }
		oClosest=$("#oClosest:checked").val();
		if(oClosest==="" || oClosest===undefined){oClosest=$("select[name='oClosest']").val();}
		if(oClosest!=="" && oClosest!==undefined){custparam=custparam+'_oClosest-'+oClosest;}
		oBudget=$("select[name='oBudget']").val();
		if(oBudget!=="" && oBudget!==undefined && oBudget!="any"){custparam=custparam+'_oBudget-'+oBudget;}
		oAge=$("select[name='oAge']").val();
		if(oAge!=="" && oAge!==undefined  && oAge!="any"){custparam=custparam+'_oAge-'+oAge;}
		focus=$("select[name='focus']").val();
		if(focus!=="" && focus!==undefined){custparam=custparam+'_focus-'+focus;}
		if($("select[name='country']").val()!==undefined && $("select[name='country']").val()!="any"){custparam=custparam+'_cntry-'+$("select[name='country']").val();}
		if($("select[name='continent']").val()!==undefined && $("select[name='continent']").val()!="any" ){custparam=custparam+'_conti-'+$("select[name='continent']").val();}

    if($("select[name='feedtype']").val()!==undefined){custparam=custparam+'_output-'+$("select[name='feedtype']").val();}
    // sets the themeID
		theme='';
		if($("input[name='themeID']").val()!="2" && id!='datafeeds'){theme='_themeID-'+$("input[name='themeID']").val();}
    if($("input[name='affID']").val()!=""){
    custparam=custparam+'_affID-'+$("input[name='affID']").val();
    }
		if($("input[name='hTitle']").val()!=""){
		htitle = $("input[name='hTitle']").val();
    custparam=custparam+'_hTitle-'+htitle.replace(/(\W)/gi,'-') ;
    }
     // sets the color values - checks that user selected values do not match defaults and then adds to URI
		colors = '';
    if(Defc9==="") {
			if(Defc1!=$("input[name='c1']").val()){colors=colors+'_c1-'+$("input[name='c1']").val();}
			if(Defc2!=$("input[name='c2']").val()){colors=colors+'_c2-'+$("input[name='c2']").val();}
			if(Defc3!=$("input[name='c3']").val()){colors=colors+'_c3-'+$("input[name='c3']").val();}
			if(Defc4!=$("input[name='c4']").val()){colors=colors+'_c4-'+$("input[name='c4']").val();}
			if(Defc5!=$("input[name='c5']").val()){colors=colors+'_c5-'+$("input[name='c5']").val();}
			if(Defc6!=$("input[name='c6']").val()){colors=colors+'_c6-'+$("input[name='c6']").val();}
			if(Defc7!=$("input[name='c7']").val()){colors=colors+'_c7-'+$("input[name='c7']").val();}
			if(Defc8!=$("input[name='c8']").val()){colors=colors+'_c8-'+$("input[name='c8']").val();}
		} else {
			if(Defc9!=$("input[name='c9']").val()){colors=colors+'_c9-'+$("input[name='c9']").val();}
			if(Defc10!=$("input[name='c10']").val()){colors=colors+'_c10-'+$("input[name='c10']").val();}
			if(Defc11!=$("input[name='c11']").val()){colors=colors+'_c11-'+$("input[name='c11']").val();}
			if(Defc12!=$("input[name='c12']").val()){colors=colors+'_c12-'+$("input[name='c12']").val();}
			if(Defc13!=$("input[name='c13']").val()){colors=colors+'_c13-'+$("input[name='c13']").val();}
			if(Defc14!=$("input[name='c14']").val()){colors=colors+'_c14-'+$("input[name='c14']").val();}
			if(Defc15!=$("input[name='c15']").val()){colors=colors+'_c15-'+$("input[name='c15']").val();}
			if(Defc16!=$("input[name='c16']").val()){colors=colors+'_c16-'+$("input[name='c16']").val();}
			if(Defc17!=$("input[name='c17']").val()){colors=colors+'_c17-'+$("input[name='c17']").val();}
			if(Defc18!=$("input[name='c18']").val()){colors=colors+'_c18-'+$("input[name='c18']").val();}
			if(Defc19!=$("input[name='c19']").val()){colors=colors+'_c19-'+$("input[name='c19']").val();}
			if(Defc20!=$("input[name='c20']").val()){colors=colors+'_c20-'+$("input[name='c20']").val();}
			if(Defc22!=$("input[name='c22']").val()){colors=colors+'_c22-'+$("input[name='c22']").val();}
			if(Defc22!=$("input[name='c22']").val()){colors=colors+'_c22-'+$("input[name='c22']").val();}
			if(Defc23!=$("input[name='c23']").val()){colors=colors+'_c23-'+$("input[name='c23']").val();}
			if(Defc24!=$("input[name='c24']").val()){colors=colors+'_c24-'+$("input[name='c24']").val();}
			if(Defc25!=$("input[name='c25']").val()){colors=colors+'_c25-'+$("input[name='c25']").val();}
			if(Defc26!=$("input[name='c26']").val()){colors=colors+'_c26-'+$("input[name='c26']").val();}
			if(Defc27!=$("input[name='c27']").val()){colors=colors+'_c27-'+$("input[name='c27']").val();}
			if(Defc28!=$("input[name='c28']").val()){colors=colors+'_c28-'+$("input[name='c28']").val();}
			if(Defc29!=$("input[name='c29']").val()){colors=colors+'_c29-'+$("input[name='c29']").val();}
			if(Defc30!=$("input[name='c30']").val()){colors=colors+'_c30-'+$("input[name='c30']").val();}
			if(Defc33!=$("input[name='c33']").val()){colors=colors+'_c33-'+$("input[name='c33']").val();}
			if(Defc32!=$("input[name='c32']").val()){colors=colors+'_c32-'+$("input[name='c32']").val();}
			if(Defc33!=$("input[name='c33']").val()){colors=colors+'_c33-'+$("input[name='c33']").val();}
			if(Defc34!=$("input[name='c34']").val()){colors=colors+'_c34-'+$("input[name='c34']").val();}
			if(Defc35!=$("input[name='c35']").val()){colors=colors+'_c35-'+$("input[name='c35']").val();}
			if(Defc36!=$("input[name='c36']").val()){colors=colors+'_c36-'+$("input[name='c36']").val();}
			if(Defc37!=$("input[name='c37']").val()){colors=colors+'_c37-'+$("input[name='c37']").val();}
			if(Defc38!=$("input[name='c38']").val()){colors=colors+'_c38-'+$("input[name='c38']").val();}
			if(Defc39!=$("input[name='c39']").val()){colors=colors+'_c39-'+$("input[name='c39']").val();}
			if(Defc40!=$("input[name='c40']").val()){colors=colors+'_c40-'+$("input[name='c40']").val();}
			if(Defc44!=$("input[name='c44']").val()){colors=colors+'_c44-'+$("input[name='c44']").val();}
			if(Defc42!=$("input[name='c42']").val()){colors=colors+'_c42-'+$("input[name='c42']").val();}
			if(Defc43!=$("input[name='c43']").val()){colors=colors+'_c43-'+$("input[name='c43']").val();}
			if(Defc44!=$("input[name='c44']").val()){colors=colors+'_c44-'+$("input[name='c44']").val();}
			if(Defc45!=$("input[name='c45']").val()){colors=colors+'_c45-'+$("input[name='c45']").val();}
			if(Defc46!=$("input[name='c46']").val()){colors=colors+'_c46-'+$("input[name='c46']").val();}
			if(Defc47!=$("input[name='c47']").val()){colors=colors+'_c47-'+$("input[name='c47']").val();}
			if(Defc48!=$("input[name='c48']").val()){colors=colors+'_c48-'+$("input[name='c48']").val();}
			if(Defc49!=$("input[name='c49']").val()){colors=colors+'_c49-'+$("input[name='c49']").val();}
			if(Defc50!=$("input[name='c50']").val()){colors=colors+'_c50-'+$("input[name='c50']").val();}
			if(Defc55!=$("input[name='c55']").val()){colors=colors+'_c55-'+$("input[name='c55']").val();}
			if(Defc52!=$("input[name='c52']").val()){colors=colors+'_c52-'+$("input[name='c52']").val();}
			if(Defc53!=$("input[name='c53']").val()){colors=colors+'_c53-'+$("input[name='c53']").val();}
			if(Defc55!=$("input[name='c55']").val()){colors=colors+'_c55-'+$("input[name='c55']").val();}
			if(Defc56!=$("input[name='c56']").val()){colors=colors+'_c56-'+$("input[name='c56']").val();}
			if(Defc57!=$("input[name='c57']").val()){colors=colors+'_c57-'+$("input[name='c57']").val();}
			if(Defc58!=$("input[name='c58']").val()){colors=colors+'_c58-'+$("input[name='c58']").val();}
			if(Defc59!=$("input[name='c59']").val()){colors=colors+'_c59-'+$("input[name='c59']").val();}
			if(Defc60!=$("input[name='c60']").val()){colors=colors+'_c60-'+$("input[name='c60']").val();}
			if(Defc61!=$("input[name='c61']").val()){colors=colors+'_c61-'+$("input[name='c61']").val();}
			if(Defc62!=$("input[name='c62']").val()){colors=colors+'_c62-'+$("input[name='c62']").val();}
			if(Defc63!=$("input[name='c63']").val()){colors=colors+'_c63-'+$("input[name='c63']").val();}
			if(Defc64!=$("input[name='c64']").val()){colors=colors+'_c64-'+$("input[name='c64']").val();}
		}
 		if($("select[name='color']").val()!="black"){colors=colors+'_color-'+$("select[name='color']").val();}
		$('#edit-theme').hide();
		$('#edit-theme-advanced').hide();
		$('#enable-filters').hide();
		$('#enable-load').hide();
		// sets iframe and source code
		src = 'http://'+window.location.hostname+'/console/api/'+theme+colors+custparam;
    	if (id=="map") {
			src=src+'_listNr-0';
  		remove_underscores();
			if (f=="_f-0") { height="470"; } else { height = "530"; }
			$('#integrate .column1 code').empty().append('&lt;iframe src="'+src+'" width="'+width+'px" height="'+height+'px" frameborder="0" scrolling="no"&gt;&lt;/iframe&gt;');
			$('#integrate .column1 .iframe').empty().append('<iframe src="'+src+'" width="'+width+'px" height="'+height+'px" frameborder="0" scrolling="no"></iframe>').show();	
		} else if (id=="list") {
		  src=src+'_mapNr-0';
  		remove_underscores();
			if (f=="_f-0") { height="470"; } else { height = "530"; }
			$('#integrate .column1 code').empty().append('&lt;iframe src="'+src+'" width="'+width+'px" height="'+height+'px" frameborder="0" scrolling="no"&gt;&lt;/iframe&gt;');
			$('#integrate .column1 .iframe').empty().append('<iframe src="'+src+'" width="'+width+'px" height="'+height+'px" frameborder="0" scrolling="no"></iframe>').show();
		} else if (id=="banner") {
		  src=src+'_mapNr-0_layout-L7_hf-0_f-0';
  		remove_underscores();
			dimensions=$("select[name='size']").val().split('x');
			$('#integrate .column1 code').empty().append('&lt;iframe src="'+src+'" width="'+dimensions[0]+'px" height="'+dimensions[1]+'px" frameborder="0" scrolling="no"&gt;&lt;/iframe&gt;');
			$('#integrate .column1 .iframe').empty().append('<iframe src="'+src+'" width="'+dimensions[0]+'px" height="'+dimensions[1]+'px" frameborder="0" scrolling="no"></iframe>').show();
		} else if (id=="console") {
  		remove_underscores();
			$('#integrate .default-iframe').hide(0);
			if (f=="_f-0") { height="470"; } else { height = "530"; }
			$('#integrate .column1 code').empty().append('&lt;iframe src="'+src+'" width="'+width+'px" height="'+height+'px" frameborder="0" scrolling="no"&gt;&lt;/iframe&gt;');
			$('#integrate .column1 .iframe').empty().append('<iframe src="'+src+'" width="'+width+'px" height="'+height+'px" frameborder="0" scrolling="no"></iframe>').show();
		} else if (id=="datafeeds") {
  		remove_underscores();
			$('#integrate .default-iframe').hide(0);
			$('#integrate .column1 code').empty().append('JSON FEED @ '+src+'_mapNr-0');
			$('#integrate .column1 .iframe').empty().append('<iframe src="'+src+'_mapNr-0_preview-1" width="700px" height="530px" frameborder="0" scrolling="no"></iframe>').show();
		}
		return false;
	});
////////////////////////////////////////////////////////////////////////////////
// default values into globals
////////////////////////////////////////////////////////////////////////////////	
	function set_defaults(){
    value=$("select[name='themes']").val().split(',');
    Defc1=value[1];
    Defc2=value[2];
    Defc3=value[3];
    Defc4=value[4];
    Defc5=value[5];
    Defc6=value[6];
    Defc7=value[7];
    Defc8=value[8];
    Defc9=value[9];
    Defc10=value[10];
    Defc11=value[11];
    Defc12=value[12];
    Defc13=value[13];
    Defc14=value[14];
    Defc15=value[15];
    Defc16=value[16];
    Defc17=value[17];
    Defc18=value[18];
    Defc19=value[19];
    Defc20=value[20];
    Defc21=value[21];
    Defc22=value[22];
    Defc23=value[23];
    Defc24=value[24];
    Defc25=value[25];
    Defc26=value[26];
    Defc27=value[27];
    Defc28=value[28];
    Defc29=value[29];
    Defc30=value[30];
    Defc31=value[31];
    Defc32=value[32];
    Defc33=value[33];
    Defc34=value[34];
    Defc35=value[35];
    Defc36=value[36];
    Defc37=value[37];
    Defc38=value[38];
    Defc39=value[39];
    Defc40=value[40];
    Defc41=value[41];
    Defc42=value[42];
    Defc43=value[43];
    Defc44=value[44];
    Defc45=value[45];
    Defc46=value[46];
    Defc47=value[47];
    Defc48=value[48];
    Defc49=value[49];
    Defc50=value[50];
    Defc51=value[51];
    Defc52=value[52];
    Defc53=value[53];
    Defc54=value[54];
    Defc55=value[55];
    Defc56=value[56];
    Defc57=value[57];
    Defc58=value[58];
    Defc59=value[59];
    Defc60=value[60];
    Defc61=value[61];
    Defc62=value[62];
    Defc63=value[63];
    Defc64=value[64];
    Defcolor=$("select[name='color']").val();
	// sets the themeID
	themeID=value[0];
	theme='';
	if(themeID!="2"){theme='_themeID-'+themeID;}
	// gets the iframe values
		if($('.default-iframe').is(':hidden') ) {
			src=$('.iframe iframe').attr('src');
			width=$('.iframe iframe').attr('width');
			height=$('.iframe iframe').attr('height');
      width = width.replace('px','');	
		  height = height.replace('px','');
		} else {
			src=$('.default-iframe').attr('src');
			width=$('.default-iframe').attr('width');
			height=$('.default-iframe').attr('height');
		  width = width.replace('px','');
		  height = height.replace('px','');
    }
	return false;
	}
////////////////////////////////////////////////////////////////////////////////
// update list sizes depending on style set
////////////////////////////////////////////////////////////////////////////////
	$('#list .layout select').live('change', function() {
		var
		layout=$("select[name='layout']").val();
		if (layout=="L8") {
			$('#list .size select').empty().append('<option value="400">400px</option><option value="300">300px</option><option value="200">200px</option><option value="180">180px</option><option value="160">160px</option>');
		} else {
			$('#list .size select').empty().append('<option value="1000">1000px</option><option value="900">900px</option><option value="800">800px</option><option value="774">774px</option><option value="770">770px</option><option value="700" selected="selected">700px</option><option value="644">644px</option><option value="600">600px</option><option value="542">542px</option>');
		}
	});
////////////////////////////////////////////////////////////////////////////////
// update list sizes depending on style set
////////////////////////////////////////////////////////////////////////////////
	$('#banner .type select').live('change', function() {
		var
		type=$("select[name='brand']").val();
		if (type=="brand") {
			$('#banner .size select').empty().append('<option value="180x160">180 x 160px</option><option value="200x200">200 x 200px</option><option value="250x166">250 x 166px</option><option value="250x250">250 x 250px</option><option value="295x196">295 x 196px</option><option value="300x250">300 x 250px</option><option value="336x280">336 x 280px</option><option value="338x225">338 x 225px</option><option value="468x60">468 x 60px</option><option value="728x90">728 x 90px</option>');
			$('#banner .brand').append('<span>Select Brand</span><select name="bb"><option value="gb">Go Ballistic</option><option value="tap" selected="selected">The Activity People</option><option value="kn">Karting Nation</option><option value="qt">Quad Trax</option><option value="qn">Quad Nation</option></select>').show();
		} else {
			$('#banner .size select').empty().append('<option value="180x160">180 x 160px</option><option value="200x200">200 x 200px</option><option value="250x166">250 x 166px</option><option value="250x250">250 x 250px</option><option value="295x196">295 x 196px</option><option value="300x250">300 x 250px</option><option value="336x280">336 x 280px</option><option value="338x225">338 x 225px</option><option value="468x60">468 x 60px</option>');
			$('#banner .brand').empty().hide();
		}
	});
////////////////////////////////////////////////////////////////////////////////
// close popups
////////////////////////////////////////////////////////////////////////////////
$('.close').live('click', function() {
	var
	parent=$(this).parent().parent();
	$(parent).hide();
});
////////////////////////////////////////////////////////////////////////////////
// enable advanced options
////////////////////////////////////////////////////////////////////////////////
	$('.advanced-options').live('click', function() {
		if($('#advanced-options').is(':hidden'))
		{$('#advanced-options').show('');} else
		{$('#advanced-options').hide() ;}
	});
////////////////////////////////////////////////////////////////////////////////
	$('.tab-container').hide(0);
	$('.tabs-selected').show(0);
	$('.tabs-menu li a').live('click', function() {
		if($(this).parent().attr('class')=="tab-selected"){
		} else {
			$('.tab-container').hide(0);
			$('.tabs-menu li').removeClass();
			var
			el = $(this).parent(),
			node = $(this).attr('href');
			$(el).addClass('tab-selected');
			$(node).show(0);
			return false;
		}
	});
////////////////////////////////////////////////////////////////////////////////
// edit theme colors
////////////////////////////////////////////////////////////////////////////////
	$('.edit-theme').live('click', function() {
		// sets default colors
		set_defaults();
		if(Defc9===""){
			if($('#edit-theme').is(':hidden'))
			{$('#edit-theme').show('') ;} else
			{$('#edit-theme').hide() ;}
		
		} else {
			if ($('#edit-theme-advanced').is(':hidden'))
			{$('#edit-theme-advanced').show('');} else
			{$('#edit-theme-advanced').hide() ;}
		}
		return false;
	});
////////////////////////////////////////////////////////////////////////////////
// loading a default theme
////////////////////////////////////////////////////////////////////////////////
	$('.themes select').live('change', function() {

		//establish default values for the theme and put in global variables for future referencing
    	set_defaults();
		$('.themeID').attr('value',''+value[0]+'');
		//if(value[9]=="") {
			$('#c1 input').attr('value',''+value[1]+'');
			$('#c1 .color').attr('style','background-color:#'+value[1]+';');	
			$('#c2 input').attr('value',''+value[2]+'');
			$('#c2 .color').attr('style','background-color:#'+value[2]+';');	
			$('#c3 input').attr('value',''+value[3]+'');
			$('#c3 .color').attr('style','background-color:#'+value[3]+';');	
			$('#c4 input').attr('value',''+value[4]+'');
			$('#c4 .color').attr('style','background-color:#'+value[4]+';');	
			$('#c5 input').attr('value',''+value[5]+'');
			$('#c5 .color').attr('style','background-color:#'+value[5]+';');	
			$('#c6 input').attr('value',''+value[6]+'');
			$('#c6 .color').attr('style','background-color:#'+value[6]+';');	
			$('#c7 input').attr('value',''+value[7]+'');
			$('#c7 .color').attr('style','background-color:#'+value[7]+';');	
			$('#c8 input').attr('value',''+value[8]+'');
			$('#c8 .color').attr('style','background-color:#'+value[8]+';');
		//} else {
			$('#c9 input').attr('value',''+value[9]+'');
			$('#c9 .color').attr('style','background-color:#'+value[9]+';');	
			$('#c10 input').attr('value',''+value[10]+'');
			$('#c10 .color').attr('style','background-color:#'+value[10]+';');	
			$('#c11 input').attr('value',''+value[11]+'');
			$('#c11 .color').attr('style','background-color:#'+value[11]+';');	
			$('#c12 input').attr('value',''+value[12]+'');
			$('#c12 .color').attr('style','background-color:#'+value[12]+';');	
			$('#c13 input').attr('value',''+value[13]+'');
			$('#c13 .color').attr('style','background-color:#'+value[13]+';');	
			$('#c14 input').attr('value',''+value[14]+'');
			$('#c14 .color').attr('style','background-color:#'+value[14]+';');	
			$('#c15 input').attr('value',''+value[15]+'');
			$('#c15 .color').attr('style','background-color:#'+value[15]+';');	
			$('#c16 input').attr('value',''+value[16]+'');
			$('#c16 .color').attr('style','background-color:#'+value[16]+';');
			$('#c17 input').attr('value',''+value[17]+'');
			$('#c17 .color').attr('style','background-color:#'+value[17]+';');	
			$('#c18 input').attr('value',''+value[18]+'');
			$('#c18 .color').attr('style','background-color:#'+value[18]+';');	
			$('#c19 input').attr('value',''+value[19]+'');
			$('#c19 .color').attr('style','background-color:#'+value[19]+';');
			$('#c20 input').attr('value',''+value[20]+'');
			$('#c20 .color').attr('style','background-color:#'+value[20]+';');	
			$('#c21 input').attr('value',''+value[21]+'');
			$('#c21 .color').attr('style','background-color:#'+value[21]+';');	
			$('#c22 input').attr('value',''+value[22]+'');
			$('#c22 .color').attr('style','background-color:#'+value[22]+';');	
			$('#c23 input').attr('value',''+value[23]+'');
			$('#c23 .color').attr('style','background-color:#'+value[23]+';');	
			$('#c24 input').attr('value',''+value[24]+'');
			$('#c24 .color').attr('style','background-color:#'+value[24]+';');	
			$('#c25 input').attr('value',''+value[25]+'');
			$('#c25 .color').attr('style','background-color:#'+value[25]+';');	
			$('#c26 input').attr('value',''+value[26]+'');
			$('#c26 .color').attr('style','background-color:#'+value[26]+';');
			$('#c27 input').attr('value',''+value[27]+'');
			$('#c27 .color').attr('style','background-color:#'+value[27]+';');	
			$('#c28 input').attr('value',''+value[28]+'');
			$('#c28 .color').attr('style','background-color:#'+value[28]+';');	
			$('#c29 input').attr('value',''+value[29]+'');
			$('#c29 .color').attr('style','background-color:#'+value[29]+';');
			$('#c30 input').attr('value',''+value[30]+'');
			$('#c30 .color').attr('style','background-color:#'+value[30]+';');	
			$('#c31 input').attr('value',''+value[31]+'');
			$('#c31 .color').attr('style','background-color:#'+value[31]+';');	
			$('#c32 input').attr('value',''+value[32]+'');
			$('#c32 .color').attr('style','background-color:#'+value[32]+';');	
			$('#c33 input').attr('value',''+value[33]+'');
			$('#c33 .color').attr('style','background-color:#'+value[33]+';');	
			$('#c34 input').attr('value',''+value[34]+'');
			$('#c34 .color').attr('style','background-color:#'+value[34]+';');	
			$('#c35 input').attr('value',''+value[35]+'');
			$('#c35 .color').attr('style','background-color:#'+value[35]+';');	
			$('#c36 input').attr('value',''+value[36]+'');
			$('#c36 .color').attr('style','background-color:#'+value[36]+';');
			$('#c37 input').attr('value',''+value[37]+'');
			$('#c37 .color').attr('style','background-color:#'+value[37]+';');	
			$('#c38 input').attr('value',''+value[38]+'');
			$('#c38 .color').attr('style','background-color:#'+value[38]+';');	
			$('#c39 input').attr('value',''+value[39]+'');
			$('#c39 .color').attr('style','background-color:#'+value[39]+';');
			$('#c40 input').attr('value',''+value[40]+'');
			$('#c40 .color').attr('style','background-color:#'+value[40]+';');	
			$('#c41 input').attr('value',''+value[41]+'');
			$('#c41 .color').attr('style','background-color:#'+value[41]+';');	
			$('#c42 input').attr('value',''+value[42]+'');
			$('#c42 .color').attr('style','background-color:#'+value[42]+';');	
			$('#c43 input').attr('value',''+value[43]+'');
			$('#c43 .color').attr('style','background-color:#'+value[43]+';');	
			$('#c44 input').attr('value',''+value[44]+'');
			$('#c44 .color').attr('style','background-color:#'+value[44]+';');	
			$('#c45 input').attr('value',''+value[45]+'');
			$('#c45 .color').attr('style','background-color:#'+value[45]+';');	
			$('#c46 input').attr('value',''+value[46]+'');
			$('#c46 .color').attr('style','background-color:#'+value[46]+';');
			$('#c47 input').attr('value',''+value[47]+'');
			$('#c47 .color').attr('style','background-color:#'+value[47]+';');	
			$('#c48 input').attr('value',''+value[48]+'');
			$('#c48 .color').attr('style','background-color:#'+value[48]+';');	
			$('#c49 input').attr('value',''+value[49]+'');
			$('#c49 .color').attr('style','background-color:#'+value[49]+';');
			$('#c50 input').attr('value',''+value[50]+'');
			$('#c50 .color').attr('style','background-color:#'+value[50]+';');	
			$('#c51 input').attr('value',''+value[51]+'');
			$('#c51 .color').attr('style','background-color:#'+value[51]+';');	
			$('#c52 input').attr('value',''+value[52]+'');
			$('#c52 .color').attr('style','background-color:#'+value[52]+';');	
			$('#c53 input').attr('value',''+value[53]+'');
			$('#c53 .color').attr('style','background-color:#'+value[53]+';');	
			$('#c54 input').attr('value',''+value[54]+'');
			$('#c54 .color').attr('style','background-color:#'+value[54]+';');	
			$('#c55 input').attr('value',''+value[55]+'');
			$('#c55 .color').attr('style','background-color:#'+value[55]+';');	
			$('#c56 input').attr('value',''+value[56]+'');
			$('#c56 .color').attr('style','background-color:#'+value[56]+';');
			$('#c57 input').attr('value',''+value[57]+'');
			$('#c57 .color').attr('style','background-color:#'+value[57]+';');	
		//}
		$('.default-iframe').hide(0);
		$('#edit-theme').hide();
		$('#edit-theme-advanced').hide();
		$('#enable-filters').hide();
		$('#enable-load').hide();
		// as theme has changed remove all references to the pre-existing theme from src as well as any custom colors
    // remove themeID
    src = src.replace(/themeID-\d+/,'');
    // remove override colors
    isrc = src.search(/(c[0-9]+-[0-9a-zA-Z]+)/);
    while (isrc != -1){
      src = src.replace(/(c[0-9]+-[0-9a-zA-Z]+)/,'');  
      isrc = src.search(/(c[0-9]+-[0-9a-zA-Z]+)/);
    }
    //add theme to src
    src=src+theme;
    // remove color value for loading graphic
    src = src.replace(/(color-[0-9a-zA-Z]+)/,'');
    remove_underscores();
    // rewrite the code for the user to paste into website
    $('.column1 code').empty().append('&lt;iframe src="'+src+'" width="'+width+'" height="'+height+'" frameborder="0" scrolling="no"&gt;&lt;/iframe&gt;');
		// rewrite the iframe preview pane
		$('.column1 .iframe').empty().append('<iframe src="'+src+'" width="'+width+'" height="'+height+'" frameborder="0" scrolling="no"></iframe>').show();
		return false;
	});	
////////////////////////////////////////////////////////////////////////////////
// remove double and leading underscores from iframe source
////////////////////////////////////////////////////////////////////////////////
	function remove_underscores(){
    //remove double underscores
    var isrc = src.search('__');
    while (isrc != -1){
      src = src.replace('__','_');  
      isrc = url.search('__');
    }
    //remove leading underscore
    src = src.replace('/api/_','/api/');
  }
////////////////////////////////////////////////////////////////////////////////
// updating text color value
////////////////////////////////////////////////////////////////////////////////
	$('.colorpicker input').live('change', function() {
		var hex=$(this).attr('value');
		var color=$(this).next();
		$(color).attr('style','background-color:#'+hex+';');
		return false;
	});	
////////////////////////////////////////////////////////////////////////////////
// color picker
////////////////////////////////////////////////////////////////////////////////
	$('.colorpicker').append('<div class="colors"></div>');
	$('.colorpicker .color').live('click', function() {
		var colors=$(this).next();
		if ($(colors).is(':hidden'))
		{$(colors).empty().fadeIn('normal').load('/marketing/colors.php') ;} else
		{$(colors).hide() ;}
		return false;
	});	
	$('.colors ul li a').live('click', function() {
		var
		hex=$(this).attr('name');
		parent=$(this).parent().parent().parent().parent().attr('id');
		$('#'+parent+' input').attr('value',''+hex+'');
		$('#'+parent+' .color').attr('style','background-color:#'+hex+';');
		$('.colors').hide();
		return false;
	});	
////////////////////////////////////////////////////////////////////////////////
// activities list //
////////////////////////////////////////////////////////////////////////////////
	$('#activities .categories div').hide();
	$('#activities #select-activity').live('click', function() {
		if($('#activities .categories div').is(':hidden')){
			$(this).addClass('hide');
			var activity = $('#activities .categories input').val();
			if(activity=="All Activities"){
				$('#activities .categories div').show().load('/console/activities');	
			} else {
				$('#activities .categories div').show();	
			}
		} else {
			$(this).removeClass();
			$('#activities .categories div').hide();
			$('#activities .categories div h3').show();
			$('#activities .categories div ul').hide();
		}
		return false;
	});
	// this sets the category filters	
	$('#activities .categories div ul').hide();
	$('#activities .categories div h3 a').live('click', function() {								   
		var h3 = $(this).parent();
		var ul = $(this).parent().next();
		if($(ul).is(':hidden')){
			$('#activities .categories div h3').not(h3).hide();
			$('#activities .categories div ul').hide();	
			$(this).addClass('hide');
			$(ul).show();
			
		} else {
			$(ul).hide();
			$(this).removeClass();
			$('#activities .categories div h3').show();
		}										   
		return false;
	});	
	// this sets the activity filters	
	var activityID_arr = {};
	var activity_arr = {};
	function actID_recal(){
		res = '';
		for (i in activityID_arr){
			if (res !== ''){res += ','+activityID_arr[i];} else {res = activityID_arr[i];}
		}
		$('#activities #activityID').val(res);
	}
	function act_recal(){
		res = '';
			for (i in activity_arr){
				if (res !== ''){res += ', '+activity_arr[i];} else {res = activity_arr[i];}
			}
		if (res === ''){
			res = "All Activities";	
			$('#activities .reset').hide();
		} else {
			$('#activities').append('<a href="#" class="reset"></a>');
		}
		$('#activities .categories input').val(res);
	}
	$('#activities .categories div li a').live('click', function() {           
		var li = $(this).parent();
		var selected = $(this).parent().attr('class');
		var activity = $(this).attr('rel');
		var activityID = $(this).attr('name');
		if(selected=='selected'){
			$(li).removeClass();
			$(this).attr('title','add to filter');
			delete activityID_arr[activityID];
			actID_recal();
			delete activity_arr[activity];
			act_recal();
		} else {
			$(li).addClass('selected');
			$(this).attr('title','remove from filter');
			activityID_arr[activityID] = activityID  ;
			actID_recal();
			activity_arr[activity] = activity  ;
			act_recal();	
		} 
		return false;
	}); 
	$('#activities .reset').live('click', function() {
		$('#activities .categories li').removeClass();
		for (i in activity_arr){
			delete activity_arr[i];
		}
		for (i in activityID_arr){
			delete activityID_arr[i];
		}
		actID_recal();
		act_recal();
		return false;
	});
////////////////////////////////////////////////////////////////////////////////
// activities list x2 //
////////////////////////////////////////////////////////////////////////////////
	$('#activities2 .categories div').hide();
	$('#activities2 #select-activity2').live('click', function() {
		if($('#activities2 .categories div').is(':hidden')){
			$(this).addClass('hide');
			var activity = $('#activities2 .categories input').val();
			if(activity=="All Activities"){
				$('#activities2 .categories div').show().load('/console/activities');	
			} else {
				$('#activities2 .categories div').show();	
			}
		} else {
			$(this).removeClass();
			$('#activities2 .categories div').hide();
			$('#activities2 .categories div h3').show();
			$('#activities2 .categories div ul').hide();
		}
		return false;
	});
	// this sets the category filters	
	$('#activities2 .categories div ul').hide();
	$('#activities2 .categories div h3 a').live('click', function() {								   
		var h3 = $(this).parent();
		var ul = $(this).parent().next();
		if($(ul).is(':hidden')){
			$('#activities2 .categories div h3').not(h3).hide();
			$('#activities2 .categories div ul').hide();	
			$(this).addClass('hide');
			$(ul).show();
			
		} else {
			$(ul).hide();
			$(this).removeClass();
			$('#activities2 .categories div h3').show();
		}										   
		return false;
	});	
	// this sets the activity filters	
	var activityID2_arr = {};
	var activity2_arr = {};
	function actID2_recal(){
		res = '';
		for (i in activityID2_arr){
			if (res !== ''){res += ','+activityID2_arr[i];} else {res = activityID2_arr[i];}
		}
		$('#activities2 #activityID2').val(res);
	}
	function act2_recal(){
		res = '';
			for (i in activity2_arr){
				if (res !== ''){res += ', '+activity2_arr[i];} else {res = activity2_arr[i];}
			}
		if (res === ''){
			res = "All Activities";	
			$('#activities2 .reset').hide();
		} else {
			$('#activities2').append('<a href="#" class="reset"></a>');
		}
		$('#activities2 .categories input').val(res);
	}
	$('#activities2 .categories div li a').live('click', function() {           
		var li = $(this).parent();
		var selected = $(this).parent().attr('class');
		var activity = $(this).attr('rel');
		var activityID = $(this).attr('name');
		if(selected=='selected'){
			$(li).removeClass();
			$(this).attr('title','add to filter');
			delete activityID2_arr[activityID];
			actID2_recal();
			delete activity2_arr[activity];
			act2_recal();
		} else {
			$(li).addClass('selected');
			$(this).attr('title','remove from filter');
			activityID2_arr[activityID] = activityID  ;
			actID2_recal();
			activity2_arr[activity] = activity  ;
			act2_recal();	
		} 
		return false;
	}); 
	$('#activities2 .reset').live('click', function() {
		$('#activities2 .categories li').removeClass();
		for (i in activity_arr){
			delete activity_arr[i];
		}
		for (i in activityID_arr){
			delete activityID_arr[i];
		}
		actID_recal();
		act_recal();
		return false;
	});
////////////////////////////////////////////////////////////////////////////////
});
////////////////////////////////////////////////////////////////////////////////
// login
////////////////////////////////////////////////////////////////////////////////
function login(){
	$.ajax({
		type: "POST", 
        url: "http://"+window.location.hostname+"/marketing/login",
        data: [
        	"email=",
        	$("input[name='signin_email']").val(),
        	"&password=",
            $("input[name='signin_password']").val()
        ].join(''),
    success: function(data){
		if (data=='failure'){
			$('#ajax_login_response').html('Password or Email Address was not recognised. Please Try Again');
		} else {
			window.location = "http://"+window.location.hostname+"/marketing";
		}
	}});
}
////////////////////////////////////////////////////////////////////////////////
// statistics
////////////////////////////////////////////////////////////////////////////////
function update_report(report, chart){
	var feed  = '/marketing/statistics_report/'+report+'/'+$("select#month").val()+'/'+$("select#year").val()+'/'+$("select#grouping").val()+'/'+$("select#affID").val()+'/'+$("select#website").val()+'/'+chart;
	var flash = '<object id="flashchart" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="481" height="353"><param name="movie" value="/charts/'+chart+'.swf?xml_file='+feed+'" /><param name="quality" value="high" /><embed name="flashchart" src="/charts/'+chart+'.swf?xml_file='+feed+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="700" height="525"></embed></object>';
	// dimensions were previously 800x600
    $('div#ajax_report').html(flash);
    return false;
}
function update_websites(){
	$('#ajax_website_list').load('/marketing/statistics_adjust_websites/'+$("select#affID").val());
}
/////////////////////////////////////////////////////////////////////////////////
//following are for Autocomplete jquery plugin
/////////////////////////////////////////////////////////////////////////////////
function findValue(li) {
      resultID = '0';
      if( li === null ) {return resultID=0;}
      // if coming from an AJAX call
      if( !!li.extra ) var sValue = li.extra[0];
      // otherwise, let's just display the value in the text box
      else var sValue = li.selectValue;
      return resultID = sValue;
}

function selectItem(li) {
    	findValue(li);
}
function formatItem(row) {
    	return row[0] + " (id: " + row[1] + ")";
}
function lookupTown(){
    	var oSuggest = $("#townsearch")[0].autocompleter;
    	oSuggest.findValue();
    	return resultID;
}
