var currentTab = 1;
var maxTabs = 5;
var queryString;
 
jQuery.noConflict();

jQuery(document).ready(function() {
	
	jQuery("#nextbutton").click(function() {
	
		jQuery(".contentTab").hide();
		currentTab = currentTab + 1;
		
		
		if((jQuery('#summary').val()==0) && (currentTab==3)){
			currentTab = currentTab + 1;
		}
		if((jQuery('#dates').val()==0) && (currentTab==4)){
			currentTab = currentTab + 1;
		}
		if(currentTab==maxTabs) 
			{				
				jQuery(this).hide();
			}
		if(currentTab==2) 
			{				
				jQuery('#instructions1').hide();
				jQuery('#instructions2').show();
			}
							
		jQuery("#content-"+currentTab).show();
		jQuery("#prevbutton").show();
		
	});		
	jQuery("#prevbutton").click(function() {

		jQuery(".contentTab").hide();
		currentTab = currentTab - 1;
		
		if((jQuery('#summary').val()==0) && (currentTab==4)){
			currentTab = currentTab - 1;
		}
		if((jQuery('#dates').val()==0) && (currentTab==3)){
			currentTab = currentTab - 1;
		}
		if(currentTab<=1) 
			{
				jQuery(this).hide();
				jQuery('#instructions2').hide();
				jQuery('#instructions1').show();
				
			}
		jQuery("#content-"+currentTab).show();
		jQuery("#nextbutton").show();
		});
		
	jQuery('#picker').colorPicker(
		{			
		  defaultColor:13, 
		  columns:13,     
		  click:function(c){
		    jQuery('#hcolor').val(c);
		  }
		});
		
	jQuery('#picker2').colorPicker(
		{			
		  defaultColor:13, 
		  columns:13,    
		  click:function(c){
		    jQuery('#scolor').val(c);
		  }
		});
		
	jQuery('#picker3').colorPicker(
		{			
		  defaultColor:13,
		  columns:13,     
		  click:function(c){
		    jQuery('#dcolor').val(c);
		  }
		});		
	jQuery("#previewbutton").click(function() {
		tmpUrl = queryString.replace(/\?/gi, "@@@");
		tmpUrl = tmpUrl.replace(/\&/gi, "|||");
		window.open('preview.cfm?scriptUrl=' + tmpUrl ,"previewWindow","status=0,toolbar=0,scrollbars=1,resizable=1,width=300,height=500");
        return false;
		});
});
	
/**********************************************************************************/

function makeCode() {	

	if(jQuery('#dates').val() == 0){
		jQuery("#datePos").hide();
		jQuery("#dateFormat").hide();
	}
	else {
		jQuery("#datePos").show();
		jQuery("#dateFormat").show();
	}
		
	dpos = jQuery('#dpos').val();
	dformat = jQuery('#dformat').val();	
	
	theCode = 'http://' + document.location.host + '/rss/widget/widget.cfm?'
		+ 'feed=' + jQuery('[name=widgfeed]:radio:checked').val()
		+ '&display=' + jQuery('#display').val()
		+ '&summary=' + jQuery('#summary').val()
		+ '&dates=' + jQuery('#dates').val();
	
	if(jQuery('#hcss').val() == ''){
		theCode = theCode + '&hface=' + jQuery('#hface').val()
			+ '&hsize=' + jQuery('#hsize').val()
			+ '&hweight=' + jQuery('#hweight').val()
			+ '&hcolor=' + jQuery('#hcolor').val();
	} else {		
		theCode = theCode + '&hcss=' + jQuery('#hcss').val();
	}
	
	if(jQuery('#summary').val() == 1){	
		if(jQuery('#scss').val() == ''){
			theCode = theCode + '&sface=' + jQuery('#sface').val()
				+ '&ssize=' + jQuery('#ssize').val()
				+ '&sweight=' + jQuery('#sweight').val()
				+ '&scolor=' + jQuery('#scolor').val();
		} else {		
			theCode = theCode + '&scss=' + jQuery('#scss').val();
		}
	}	
	
	if(jQuery('#dates').val() == 1){
		theCode = theCode + '&dpos=' + jQuery('#dpos').val() + '&dformat=' + jQuery('#dformat').val();	
		if(jQuery('#dcss').val() == ''){
			theCode = theCode + '&dface=' + jQuery('#dface').val()
				+ '&dsize=' + jQuery('#dsize').val()
				+ '&dweight=' + jQuery('#dweight').val()
				+ '&dcolor=' + jQuery('#dcolor').val();
		} else {		
			theCode = theCode + '&dcss=' + jQuery('#dcss').val();
		}			
	}		
	
	queryString = theCode.replace(/#/gi, "");	
	jQuery('#pcaWidgetCodeArea').val('<scri' + 'pt type="text/javascript" src="' + queryString + '"></scri' + 'pt>');

}