/**
 *  Stroke <-> Fill 0.4.2
 *
 *  Ken Frederick
 *  ken.frederick@gmx.de
 *
 *  http://cargocollective.com/kenfrederick/
 *  http://kenfrederick.blogspot.com/
 *
 *	0.1
 *	- initial release
 *	
 *	0.2
 *	- included stroke+fill flip 
 *	
 *	0.3
 *	- added random capability
 *
 *	0.3.2
 *	- updated to 2.5 api
 *
 *	0.4.2
 *	- updated to 2.9 api
 *
 */


// ------------------------------------------------------------------------
// properties
// ------------------------------------------------------------------------

/**
 *  Note from the Scriptographer.org Team
 *  
 *  In Scriptographer 2.9, we switched to a top-down coordinate system and
 *  degrees for angle units as an easier alternative to radians.
 *  
 *  For backward compatibility we offer the possibility to still use the old
 *  bottom-up coordinate system and radians for angle units, by setting the two
 *  values bellow. Read more about this transition on our website:
 *  http://scriptographer.org/news/version-2.9.064-arrived/
 */

script.coordinateSystem = 'bottom-up';
script.angleUnits = 'radians';

// document properties
//var sel = activeDocument.selectedItems;
var sel;

// values
var values = {
	RANDOM: false
};

// gui components
var components = {
	RANDOM: { 
		type: 'checkbox',
		label: 'random'
	},

	// ------------------------------------
	// apply that shit!
	// ------------------------------------
	submit: { 
		type: 'button', 
		value: 'Apply',
		onClick: function() {
			Main();
		}
	}
};


// ------------------------------------------------------------------------
// Setup
// ------------------------------------------------------------------------


function Setup() {
	// initialize the palette window
	var palette = new Palette('Stroke <-> Fill 0.4.2', components, values);
}


// ------------------------------------------------------------------------
// Update
// ------------------------------------------------------------------------
function Update() {
}


// ------------------------------------------------------------------------
// Main
// ------------------------------------------------------------------------
function Main() {
	// document properties
	sel = activeDocument.getItems( { type: Item, selected: true } );

	//print(sel.length);
	for( i in sel ) {
		obj = sel[i];
		print(obj);

		if(values.RANDOM) {
			rand = parseInt(Math.random()*3);
		} else {
			rand = 0;
		}

		if(rand == 0) {
			//stroked!
			if(obj.strokeColor != null && obj.fillColor == null) {
				var s_color = obj.strokeColor
	
				obj.fillColor = s_color;
				obj.strokeColor = null;
	
			//filled!
			} else if(obj.strokeColor == null && obj.fillColor != null) {
				var f_color = obj.fillColor
	
				obj.strokeColor = f_color;
				obj.fillColor = null;
	
			//stroked + filled!
			} else if(obj.fillColor != null && obj.strokeColor != null) {
				var s_color = obj.strokeColor
				var f_color = obj.fillColor
	
				obj.strokeColor = f_color;
				obj.fillColor = s_color;
			}
		}
	}

}


// ------------------------------------------------------------------------
// Execution
// ------------------------------------------------------------------------
Setup();
Update();
//Main();



