/* Usage
 *
 * initialize te styleswitcher
 * window.onload=init_switch;
 * -or-
 * addLoadEvent(init_switch);
 *
 * use onclick event to trigger Eg. 
 * onclick="style_switch.set_style('visible')"
 * onclick="style_switch.set_style('default')"
 *
 * add extra style in window.onload thru:
 * style_switch.add_style(name, location_algemeen, location_navigatie, location_boxes)
 *
 */ 

if (!intraxxion)

  intraxxion = {};

  

intraxxion.styleswitcher = function() {

	this.styles = [

		{'name':'default',

		 'sheets':[

			'DesignerStyles/algemeen.css',

      'DesignerStyles/navigatie.css',

      'DesignerStyles/navigatiehome.css',

			'DesignerStyles/boxes.css']

		},

		{'name':'visible',

		 'sheets':[

			'DesignerStyles/algemeen_sz.css',

			'DesignerStyles/navigatie_sz.css',

           'DesignerStyles/navigatiehome_sz.css',

			'DesignerStyles/boxes_sz.css']

		}

	];

	this.currentstyle = 'default';

};



intraxxion.styleswitcher.prototype = {

	"initialize":function() {

		// Get stored value from cookie, if nothing found use 'default'

		if (this.get_from_cookie() == null)

			return

		this.set_style(this.cookie);



	},

	"addstyle":function(name, algemeen, navigatie, navigatiehome, boxes) {

		this.styles.push({name:[algemeen,navigatie, navigatiehome, boxes]});

	},

	"set_style":function(name) {

		for (a=0;a<this.styles.length;a++) {

			st = this.styles[a];

			if (st.name == name) {

			  try {

  			  $('cssalgemeen').href = st.sheets[0];

			  } catch(e) {}

        try {

          $('cssnavigatie').href = st.sheets[1];

        } catch(e) {}

        try {

          $('cssnavigatiehome').href = st.sheets[2];

        } catch(e) {}

        try {

			    $('cssboxes').href =  st.sheets[3];

        } catch(e) {}

			  this.current_style = name;

			  this.store_in_cookie(365);

			  break;

			}

		}

	},

	"store_in_cookie":function(days) {

		//format expiry date

		this.date = new Date();

		this.date.setTime(this.date.getTime() + ( days *24*60*60*1000));



		//store the string, replacing spaces with '#' so that leading spaces are preserved

		this.info = this.current_style.replace(/ /g,'#');



		//if the value is empty, set its expiry in the past to delete the cookie

		if(this.info == '') { this.date.setTime(0); }



		//create the cookie

		document.cookie = 'intraxxion_styleswitcher =' + this.info

			+ '; expires=' + this.date.toGMTString()

			+ '; path=/';

	},

	"get_from_cookie":function() {

		this.cookie = null;



		if(document.cookie) {

			if(document.cookie.indexOf('intraxxion_styleswitcher')!=-1) {

			//extract and store relevant information (turning '#' back into spaces)

			this.cookie = document.cookie.split('intraxxion_styleswitcher=');

			this.cookie = this.cookie[1].split(';');

			this.cookie = this.cookie[0].replace(/#/g,' ');

			}

		}

		return this.cookie

	}

};

var style_switch = new intraxxion.styleswitcher();

function init_switch() {

	style_switch.initialize();

}


