/**
 * Observer - Observe formelements for changes
 *
 * @version		1.0rc3
 *
 * @license		MIT-style license
 * @author		Harald Kirschner <mail [at] digitarald.de>
 * @copyright	Author
 */
var Observer = new Class({

	Implements: [Options, Events],

	options: {
		periodical: false,
		delay: 1000
	},

	initialize: function(el, onFired, options){
		this.setOptions(options);
		this.addEvent('onFired', onFired);
		this.element = $(el) || $$(el);
		this.value = this.element.get('value');
		if (this.options.periodical) this.timer = this.changed.periodical(this.options.periodical, this);
		else this.element.addEvent('keyup', this.changed.bind(this));
	},

	changed: function() {
		var value = this.element.get('value');
		if ($equals(this.value, value)) return;
		this.clear();
		this.value = value;
		this.timeout = this.onFired.delay(this.options.delay, this);
	},

	setValue: function(value) {
		this.value = value;
		this.element.set('value', value);
		return this.clear();
	},

	onFired: function() {
		this.fireEvent('onFired', [this.value, this.element]);
	},

	clear: function() {
		$clear(this.timeout || null);
		return this;
	}

});

var $equals = function(obj1, obj2) {
	return (obj1 == obj2 || JSON.encode(obj1) == JSON.encode(obj2));
};

/**
 * Autocompleter
 *
 * @version		1.1.1
 *
 * @todo: Caching, no-result handling!
 *
 *
 * @license		MIT-style license
 * @author		Harald Kirschner <mail [at] digitarald.de>
 * @copyright	Author
 */
var Autocompleter = {};

Autocompleter.Base = new Class({

	options: {
		minLength: 1,
		markQuery: true,
		width: false,
		maxChoices: 20,
		injectChoice: null,
		customChoices: null,
		className: 'autocompleter-choices',
		zIndex: 42,
		delay: 0,
		observerOptions: {},
		fxOptions: {},
		onOver: $empty,
		onSelect: $empty,
		onSelection: $empty,
		onShow: $empty,
		onHide: $empty,
		onBlur: $empty,
		onFocus: $empty,

		autoSubmit: true,
		overflow: false,
		overflowMargin: 25,
		selectFirst: false,
		filter: null,
		filterCase: false,
		filterSubset: false,
		forceSelect: false,
		selectMode: false,
		choicesMatch: null,

		multiple: false,
		separator: ', ',
		separatorSplit: /\s*[,;]\s*/,
		autoTrim: true,
		allowDupes: false,

		cache: true,
		relative: false
	},

	initialize: function(element, options) {
		this.element = $(element);
		this.setOptions(options);
		this.build();
		this.observer = new Observer(this.element, this.prefetch.bind(this), $merge({
			'delay': this.options.delay
		}, this.options.observerOptions));
		this.queryValue = null;
		if (this.options.filter) this.filter = this.options.filter.bind(this);
		var mode = this.options.selectMode;
		this.typeAhead = (mode == 'type-ahead');
		this.selectMode = (mode === true) ? 'selection' : mode;
		this.cached = [];
	},

	/**
	 * build - Initialize DOM
	 *
	 * Builds the html structure for choices and appends the events to the element.
	 * Override this function to modify the html generation.
	 */
	build: function() {
		if ($(this.options.customChoices)) {
			this.choices = this.options.customChoices;
		} else {
			this.choices = new Element('ul', {
				'class': this.options.className,
				'styles': {
					'zIndex': this.options.zIndex
				}
			}).inject(document.body);
			this.relative = false;
			if (this.options.relative) {
				this.choices.inject(this.element, 'after');
				this.relative = this.element.getOffsetParent();
			}
			this.fix = new OverlayFix(this.choices);
		}
		if (!this.options.separator.test(this.options.separatorSplit)) {
			this.options.separatorSplit = this.options.separator;
		}
		this.fx = (!this.options.fxOptions) ? null : new Fx.Tween(this.choices, $merge({
			'property': 'opacity',
			'link': 'cancel',
			'duration': 200
		}, this.options.fxOptions)).addEvent('onStart', Chain.prototype.clearChain).set(0);
		this.element.setProperty('autocomplete', 'off')
			.addEvent((Browser.Engine.trident || Browser.Engine.webkit) ? 'keydown' : 'keypress', this.onCommand.bind(this))
			.addEvent('click', this.onCommand.bind(this, [false]))
			.addEvent('focus', this.toggleFocus.create({bind: this, arguments: true, delay: 100}))
			.addEvent('blur', this.toggleFocus.create({bind: this, arguments: false, delay: 100}));
	},

	destroy: function() {
		if (this.fix) this.fix.destroy();
		this.choices = this.selected = this.choices.destroy();
	},

	toggleFocus: function(state) {
		this.focussed = state;
		if (!state) this.hideChoices(true);
		this.fireEvent((state) ? 'onFocus' : 'onBlur', [this.element]);
	},

	onCommand: function(e) {
		if (!e && this.focussed) return this.prefetch();
		if (e && e.key && !e.shift) {
			switch (e.key) {
				case 'enter':
					if (this.element.value != this.opted) return true;
					if (this.selected && this.visible) {
						this.choiceSelect(this.selected);
						return !!(this.options.autoSubmit);
					}
					break;
				case 'up': case 'down':
					if (!this.prefetch() && this.queryValue !== null) {
						var up = (e.key == 'up');
						this.choiceOver((this.selected || this.choices)[
							(this.selected) ? ((up) ? 'getPrevious' : 'getNext') : ((up) ? 'getLast' : 'getFirst')
						](this.options.choicesMatch), true);
					}
					return false;
				case 'esc': case 'tab':
					this.hideChoices(true);
					break;
			}
		}
		return true;
	},

	setSelection: function(finish) {
		var input = this.selected.inputValue, value = input;
		var start = this.queryValue.length, end = input.length;
		if (input.substr(0, start).toLowerCase() != this.queryValue.toLowerCase()) start = 0;
		if (this.options.multiple) {
			var split = this.options.separatorSplit;
			value = this.element.value;
			start += this.queryIndex;
			end += this.queryIndex;
			var old = value.substr(this.queryIndex).split(split, 1)[0];
			value = value.substr(0, this.queryIndex) + input + value.substr(this.queryIndex + old.length);
			if (finish) {
				var space = /[^\s,]+/;
				var tokens = value.split(this.options.separatorSplit).filter(space.test, space);
				if (!this.options.allowDupes) tokens = [].combine(tokens);
				var sep = this.options.separator;
				value = tokens.join(sep) + sep;
				end = value.length;
			}
		}
		this.observer.setValue(value);
		this.opted = value;
		if (finish || this.selectMode == 'pick') start = end;
		this.element.selectRange(start, end);
		this.fireEvent('onSelection', [this.element, this.selected, value, input]);
	},

	showChoices: function() {
		var match = this.options.choicesMatch, first = this.choices.getFirst(match);
		this.selected = this.selectedValue = null;
		if (this.fix) {
			var pos = this.element.getCoordinates(this.relative), width = this.options.width || 'auto';
			this.choices.setStyles({
				'left': pos.left,
				'top': pos.bottom,
				'width': (width === true || width == 'inherit') ? pos.width : width
			});
		}
		if (!first) return;
		if (!this.visible) {
			this.visible = true;
			this.choices.setStyle('display', '');
			if (this.fx) this.fx.start(1);
			this.fireEvent('onShow', [this.element, this.choices]);
		}
		if (this.options.selectFirst || this.typeAhead || first.inputValue == this.queryValue) this.choiceOver(first, this.typeAhead);
		var items = this.choices.getChildren(match), max = this.options.maxChoices;
		var styles = {'overflowY': 'hidden', 'height': ''};
		this.overflown = false;
		if (items.length > max) {
			var item = items[max - 1];
			styles.overflowY = 'scroll';
			styles.height = item.getCoordinates(this.choices).bottom;
			this.overflown = true;
		};
		this.choices.setStyles(styles);
		this.fix.show();
	},

	hideChoices: function(clear) {
		if (clear) {
			var value = this.element.value;
			if (this.options.forceSelect) value = this.opted;
			if (this.options.autoTrim) {
				value = value.split(this.options.separatorSplit).filter($arguments(0)).join(this.options.separator);
			}
			this.observer.setValue(value);
		}
		if (!this.visible) return;
		this.visible = false;
		this.observer.clear();
		var hide = function(){
			this.choices.setStyle('display', 'none');
			this.fix.hide();
		}.bind(this);
		if (this.fx) this.fx.start(0).chain(hide);
		else hide();
		this.fireEvent('onHide', [this.element, this.choices]);
	},

	prefetch: function() {
		var value = this.element.value, query = value;
		if (this.options.multiple) {
			var split = this.options.separatorSplit;
			var values = value.split(split);
			var index = this.element.getCaretPosition();
			var toIndex = value.substr(0, index).split(split);
			var last = toIndex.length - 1;
			index -= toIndex[last].length;
			query = values[last];
		}
		if (query.length < this.options.minLength) {
			this.hideChoices();
		} else {
			if (query === this.queryValue || (this.visible && query == this.selectedValue)) {
				if (this.visible) return false;
				this.showChoices();
			} else {
				this.queryValue = query;
				this.queryIndex = index;
				if (!this.fetchCached()) this.query();
			}
		}
		return true;
	},

	fetchCached: function() {
		return false;
		if (!this.options.cache
			|| !this.cached
			|| !this.cached.length
			|| this.cached.length >= this.options.maxChoices
			|| this.queryValue) return false;
		this.update(this.filter(this.cached));
		return true;
	},

	update: function(tokens) {
		this.choices.empty();
		this.cached = tokens;
		if (!tokens || !tokens.length) {
			this.hideChoices();
		} else {
			if (this.options.maxChoices < tokens.length && !this.options.overflow) tokens.length = this.options.maxChoices;
			tokens.each(this.options.injectChoice || function(token){
				var choice = new Element('li', {'html': this.markQueryValue(token)});
				choice.inputValue = token;
				this.addChoiceEvents(choice).inject(this.choices);
			}, this);
			this.showChoices();
		}
	},

	choiceOver: function(choice, selection) {
		if (!choice || choice == this.selected) return;
		if (this.selected) this.selected.removeClass('autocompleter-selected');
		this.selected = choice.addClass('autocompleter-selected');
		this.fireEvent('onSelect', [this.element, this.selected, selection]);
		if (!selection) return;
		this.selectedValue = this.selected.inputValue;
		if (this.overflown) {
			var coords = this.selected.getCoordinates(this.choices), margin = this.options.overflowMargin,
				top = this.choices.scrollTop, height = this.choices.offsetHeight, bottom = top + height;
			if (coords.top - margin < top && top) this.choices.scrollTop = Math.max(coords.top - margin, 0);
			else if (coords.bottom + margin > bottom) this.choices.scrollTop = Math.min(coords.bottom - height + margin, bottom);
		}
		if (this.selectMode) this.setSelection();
	},

	choiceSelect: function(choice) {
		if (choice) this.choiceOver(choice);
		this.setSelection(true);
		this.queryValue = false;
		this.hideChoices();
	},

	filter: function(tokens) {
		var regex = new RegExp(((this.options.filterSubset) ? '' : '^') + this.queryValue.escapeRegExp(), (this.options.filterCase) ? '' : 'i');
		return (tokens || this.tokens).filter(regex.test, regex);
	},

	/**
	 * markQueryValue
	 *
	 * Marks the queried word in the given string with <span class="autocompleter-queried">*</span>
	 * Call this i.e. from your custom parseChoices, same for addChoiceEvents
	 *
	 * @param		{String} Text
	 * @return		{String} Text
	 */
	markQueryValue: function(str) {
		return (!this.options.markQuery || !this.queryValue) ? str
			: str.replace(new RegExp('(' + ((this.options.filterSubset) ? '' : '^') + this.queryValue.escapeRegExp() + ')', (this.options.filterCase) ? '' : 'i'), '<span class="autocompleter-queried">$1</span>');
	},

	/**
	 * addChoiceEvents
	 *
	 * Appends the needed event handlers for a choice-entry to the given element.
	 *
	 * @param		{Element} Choice entry
	 * @return		{Element} Choice entry
	 */
	addChoiceEvents: function(el) {
		return el.addEvents({
			'mouseover': this.choiceOver.bind(this, [el]),
			'click': this.choiceSelect.bind(this, [el])
		});
	}
});

Autocompleter.Base.implement(new Events);
Autocompleter.Base.implement(new Options);

Autocompleter.Local = new Class({

	Extends: Autocompleter.Base,

	options: {
		minLength: 0,
		delay: 200
	},

	initialize: function(element, tokens, options) {
		this.parent(element, options);
		this.tokens = tokens;
	},

	query: function() {
		this.update(this.filter());
	}

});

Autocompleter.Ajax = {};

Autocompleter.Ajax.Base = new Class({

	Extends: Autocompleter.Base,

	options: {
		postVar: 'value',
		postData: {},
		ajaxOptions: {},
		onRequest: $empty,
		onComplete: $empty
	},

	initialize: function(element, options) {
		this.parent(element, options);
		var indicator = $(this.options.indicator);
		if (indicator) {
			this.addEvents({
				'onRequest': indicator.show.bind(indicator),
				'onComplete': indicator.hide.bind(indicator)
			}, true);
		}
	},

	query: function(){
		var data = $unlink(this.options.postData);
		data[this.options.postVar] = this.queryValue;
		this.fireEvent('onRequest', [this.element, this.request, data, this.queryValue]);
		this.request.send({'data': data});
	},

	/**
	 * queryResponse - abstract
	 *
	 * Inherated classes have to extend this function and use this.parent(resp)
	 *
	 * @param		{String} Response
	 */
	queryResponse: function() {
		this.fireEvent('onComplete', [this.element, this.request, this.response]);
	}

});

Autocompleter.Ajax.Json = new Class({

	Extends: Autocompleter.Ajax.Base,

	initialize: function(el, url, options) {
		this.parent(el, options);
		this.request = new Request.JSON($merge({
			'url': url,
			'link': 'cancel'
		}, this.options.ajaxOptions)).addEvent('onComplete', this.queryResponse.bind(this));
	},

	queryResponse: function(response) {
		this.parent();
		this.update(response);
	}

});

Autocompleter.Ajax.Xhtml = new Class({

	Extends: Autocompleter.Ajax.Base,

	initialize: function(el, url, options) {
		this.parent(el, options);
		this.request = new Request.HTML($merge({
			'url': url,
			'link': 'cancel',
			'update': this.choices
		}, this.options.ajaxOptions)).addEvent('onComplete', this.queryResponse.bind(this));
	},

	queryResponse: function(tree, elements) {
		this.parent();
		if (!elements || !elements.length) {
			this.hideChoices();
		} else {
			this.choices.getChildren(this.options.choicesMatch).each(this.options.injectChoice || function(choice) {
				var value = choice.innerHTML;
				choice.inputValue = value;
				this.addChoiceEvents(choice.set('html', this.markQueryValue(value)));
			}, this);
			this.showChoices();
		}

	}

});


var OverlayFix = new Class({

	initialize: function(el) {
		if (Browser.Engine.trident) {
			this.element = $(el);
			this.relative = this.element.getOffsetParent();
			this.fix = new Element('iframe', {
				'frameborder': '0',
				'scrolling': 'no',
				'src': 'javascript:false;',
				'styles': {
					'position': 'absolute',
					'border': 'none',
					'display': 'none',
					'filter': 'progid:DXImageTransform.Microsoft.Alpha(opacity=0)'
				}
			}).inject(this.element, 'after');
		}
	},

	show: function() {
		if (this.fix) {
			var coords = this.element.getCoordinates(this.relative);
			delete coords.right;
			delete coords.bottom;
			this.fix.setStyles($extend(coords, {
				'display': '',
				'zIndex': (this.element.getStyle('zIndex') || 1) - 1
			}));
		}
		return this;
	},

	hide: function() {
		if (this.fix) this.fix.setStyle('display', 'none');
		return this;
	},

	destroy: function() {
		this.fix = this.fix.destroy();
	}

});

/**
 * @todo Clean that up or check if they exist already
 */
Element.implement({

	getOffsetParent: function() {
		var body = this.getDocument().body;
		if (this == body) return null;
		if (!Browser.Engine.trident) return $(this.offsetParent);
		var el = this;
		while ((el = el.parentNode)){
			if (el == body || Element.getComputedStyle(el, 'position') != 'static') return $(el);
		}
		return null;
	},

	getCaretPosition: function() {
		if (!Browser.Engine.trident) return this.selectionStart;
		this.focus();
		var work = document.selection.createRange();
		var all = this.createTextRange();
		work.setEndPoint('StartToStart', all);
		return work.text.length;
	},

	selectRange: function(start, end) {
		if (Browser.Engine.trident) {
			var range = this.createTextRange();
			range.collapse(true);
			range.moveEnd('character', end);
			range.moveStart('character', start);
			range.select();
		} else {
			this.focus();
			this.setSelectionRange(start, end);
		}
		return this;
	}

});

/* FLOATING IMAGE */

/*
Simple Image Trail script- By JavaScriptKit.com
Visit http://www.javascriptkit.com for this script and more
This notice must stay intact
*/

var offsetfrommouse=[5,5]; //image x,y offsets from cursor position in pixels. Enter 0,0 for no offset
var displayduration=0; //duration in seconds image should remain visible. 0 for always.
var currentimageheight = 270;	// maximum image size.

if (document.getElementById || document.all){
	document.write('<div id="trailimageid">');
	document.write('</div>');
}

function gettrailobj(){
if (document.getElementById && document.getElementById("trailimageid"))
return document.getElementById("trailimageid").style
else if (document.all)
return document.all.trailimagid.style
}

function gettrailobjnostyle(){
if (document.getElementById && document.getElementById("trailimageid"))
return document.getElementById("trailimageid")
else if (document.all)
return document.all.trailimagid
}


function truebody(){
return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function showtrail1(){
	
}

function showtrail(imagename,type,title,width,height,catid,copyright,description){
	


	document.onmousemove=followmouse;

	var newHTML = '<table border="0" width="240" cellpadding="3" cellspacing="3">';
	newHTML = newHTML + '<tr><td width="100%" valign="top">';
	newHTML = newHTML + '<table class="thin" width="222">';
	newHTML = newHTML + '<tr><td width="100%"><table border="0" width="100%" cellspacing="0" cellpadding="0">';
	newHTML = newHTML + '<tr><td width="100%"><p align="center">';

	if(type=='photo'){
		newHTML = newHTML + '<div align="center" style="padding:5px;background:#fff;border:solid 1px #000">';
		newHTML = newHTML + '<img src="' + imagename + '" border="0"">';
		newHTML = newHTML + '</div>';
	}
	if(type=='video') {
		
		var browser=navigator.appName;
		var b_version=navigator.appVersion;
		var version=parseFloat(b_version);
		if ((browser=="Microsoft Internet Explorer") && (version>=4)){
			extra1 = "";
			extra2 = "";
		}else{
			extra1 = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="'+width+'" height="'+height+'">';
			extra2 = '</object>';
		}
		
		temp = 	'<div style="border:solid 5px #fff;width:'+width+'px;height:'+height+'">'+extra1+'<embed'
		+'		src="http://'+window.location.hostname+'/flash/player.swf"'
		+'		width="'+width+'"'
		+'		height="'+height+'"'
		+'		allowscriptaccess="sameDomain"'
		+'		allowfullscreen="false"'
		+'		flashvars=autostart=true&repeat=true&height='+height+'&width='+width+'&file='+imagename+'&searchbar=false&showicons=false&shownavigation=false&showdigits=false&usefullscreen=false"'
		+'		/>'+extra2+'</div>';

		newHTML = newHTML + '<div align="center" style="border:solid 1px #000">';
		newHTML = newHTML += temp;
		newHTML = newHTML + '</div>';
	}


	gettrailobjnostyle().innerHTML = newHTML;

	gettrailobj().visibility="visible";

}


function hidetrail(){
	gettrailobj().visibility="hidden"
	gettrailobjnostyle().innerHTML=""
	document.onmousemove=""
	gettrailobj().left="-500px"
}


function followmouse(e){

	var xcoord=offsetfrommouse[0]
	var ycoord=offsetfrommouse[1]

	if (typeof e != "undefined"){
		xcoord+=e.pageX
		ycoord+=e.pageY

	} else if (typeof window.event != "undefined"){
		xcoord+=truebody().scrollLeft+event.clientX
		ycoord+=truebody().scrollTop+event.clientY
	}

	var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15
	var docheight=document.all? Math.max(truebody().scrollHeight, truebody().clientHeight) : Math.max(document.body.offsetHeight, window.innerHeight)

	gettrailobj().left=xcoord+"px"
	gettrailobj().top=ycoord+"px"

}

/* MINE */

window.onload = function(){
	$('products_button').onmouseover=function(){ $('products_button').src = 'http://'+window.location.hostname+'/assets/public/images/vc_cool/template/products_over.jpg'; };
	$('products_button').onmouseout=function(){ $('products_button').src = 'http://'+window.location.hostname+'/assets/public/images/vc_cool/template/products.jpg'; };
	$('purchase_button').onmouseover=function(){ $('purchase_button').src = 'http://'+window.location.hostname+'/assets/public/images/vc_cool/template/purchase_over.jpg'; };
	$('purchase_button').onmouseout=function(){ $('purchase_button').src = 'http://'+window.location.hostname+'/assets/public/images/vc_cool/template/purchase.jpg'; };
	$('support_button').onmouseover=function(){ $('support_button').src = 'http://'+window.location.hostname+'/assets/public/images/vc_cool/template/support_over.jpg'; };
	$('support_button').onmouseout=function(){ $('support_button').src = 'http://'+window.location.hostname+'/assets/public/images/vc_cool/template/support.jpg'; };
	$('blog_button').onmouseover=function(){ $('blog_button').src = 'http://'+window.location.hostname+'/assets/public/images/vc_cool/template/blog_over.jpg'; };
	$('blog_button').onmouseout=function(){ $('blog_button').src = 'http://'+window.location.hostname+'/assets/public/images/vc_cool/template/blog.jpg'; };
	$('forum_button').onmouseover=function(){ $('forum_button').src = 'http://'+window.location.hostname+'/assets/public/images/vc_cool/template/forum_over.jpg'; };
	$('forum_button').onmouseout=function(){ $('forum_button').src = 'http://'+window.location.hostname+'/assets/public/images/vc_cool/template/forum.jpg'; };
	$('tutorials_button').onmouseover=function(){ $('tutorials_button').src = 'http://'+window.location.hostname+'/assets/public/images/vc_cool/template/tutorials_over.jpg'; };
	$('tutorials_button').onmouseout=function(){ $('tutorials_button').src = 'http://'+window.location.hostname+'/assets/public/images/vc_cool/template/tutorials.jpg'; };
	$('contact_button').onmouseover=function(){ $('contact_button').src = 'http://'+window.location.hostname+'/assets/public/images/vc_cool/template/contact_over.jpg'; };
	$('contact_button').onmouseout=function(){ $('contact_button').src = 'http://'+window.location.hostname+'/assets/public/images/vc_cool/template/contact.jpg'; };
};

if (document.images){
	preload_image_object = new Image();
	// set image url
	image_url = new Array();
	image_url[0] = 'http://'+window.location.hostname+'/assets/public/images/vc_cool/template/products_over.jpg';
	image_url[1] = 'http://'+window.location.hostname+'/assets/public/images/vc_cool/template/purchase_over.jpg';
	image_url[2] = 'http://'+window.location.hostname+'/assets/public/images/vc_cool/template/support_over.jpg';
	image_url[3] = 'http://'+window.location.hostname+'/assets/public/images/vc_cool/template/blog_over.jpg';
	image_url[4] = 'http://'+window.location.hostname+'/assets/public/images/vc_cool/template/forum_over.jpg';
	image_url[5] = 'http://'+window.location.hostname+'/assets/public/images/vc_cool/template/tutorials_over.jpg';
	image_url[6] = 'http://'+window.location.hostname+'/assets/public/images/vc_cool/template/contact_over.jpg';
	image_url[7] = 'http://'+window.location.hostname+'/assets/public/images/template/mainbg.jpg';
	image_url[8] = 'http://'+window.location.hostname+'/assets/public/images/blog/sidebar/free_tutorials_item_bg_over.jpg';
	var i = 0;
	for(i=0; i<=11; i++)
	preload_image_object.src = image_url[i];
}


function tutorial_sidebar(url,action){
	action = action || null;
	if(!action){
		window.location = url;
	}else{
		window.open(url);
	}
}

function clearSearch(value){
	if($("q").value==''){
		$("q").value = value;
		$("q").style.color = "#EEE";
	}else if($("q").value==value){
		$("q").value = '';
		$("q").style.color = "#FFF";
	}
}

function clearMainSearch(id){
	if($(id).value == 'Search Video Copilot'){
		$(id).value = '';
		$(id).style.color = "#000000";
	}else if($(id).value == ''){
		$(id).value = 'Search Video Copilot';
		$(id).style.color = "#999999";
	}
}

function search(){
	search_query = $("search_field").value;
	window.location="<?=site_url()?>search/q/"+search_query+"/";
}

function insertAtCursor(myField, myValue) {
	//IE support
	if (document.selection) {
		myField.focus();
		sel = document.selection.createRange();
		sel.text = myValue;
	}
	//MOZILLA/NETSCAPE support
	else if (myField.selectionStart || myField.selectionStart == '0') {
		var startPos = myField.selectionStart;
		var endPos = myField.selectionEnd;
		myField.value = myField.value.substring(0, startPos)
		+ myValue
		+ myField.value.substring(endPos, myField.value.length);
	} else {
		myField.value += myValue;
	}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

/*
window.addEvent('domready', function(){
	var searchInput = $('main_search');
	var indicator = $('main_search_indicator');
	indicator.setStyle('display', 'none');
	var completer = new Autocompleter.Ajax.Xhtml(searchInput, 'http://'+window.location.hostname+'/search/ajaxsearch/', {
		'postData': {html: 1},
		'onRequest': function(el) {
			indicator.setStyle('display', '');
		},
		'onComplete': function(el) {
			indicator.setStyle('display', 'none');
		},
		'parseChoices': function(el) {
			var value = el.getFirst().get('html');
			el.inputValue = value;
			this.addChoiceEvents(el).getFirst().set('html', this.markQueryValue(value));
		},
		'onSelection': function(el,selection) {
			parent.location=selection.getProperty('url');
		 	searchInput.value = selection.getProperty('title');
		}
	});
});
*/

function submitEnter(myfield,e)
{
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;

if (keycode == 13)
   {
   search();
   return false;
   }
else
   return true;
}

var button_on = 'all_categories';
function categoryClickButton(id){
	$(button_on+"_search_button").style.background = "#fff";
	$(button_on+"_search_button").style.fontWeight = "normal";
	$(id+"_search_button").style.background = "#e0f3fa";
	$(id+"_search_button").style.fontWeight = "bold";
	if(id == 'all_categories'){
		if($('products') != null){
			$('products').style.display = '';
		}
		if($('tutorials') != null){
			$('tutorials').style.display = '';
		}
		if($('presets') != null){
			$('presets').style.display = '';
		}
		if($('blog') != null){
			$('blog').style.display = '';
		}
	}
	if(id == 'products' && $(id) != null){
		if($(id) != null){
			$(id).style.display = '';
		}
		if($('presets') != null){
			$('presets').style.display = 'none';
		}
		if($('tutorials') != null){
			$('tutorials').style.display = 'none';
		}
		if($('blog') != null){
			$('blog').style.display = 'none';
		}
	}
	if(id == 'tutorials' && $(id) != null){
		if($(id) != null){
			$(id).style.display = '';
		}
		if($('products') != null){
			$('products').style.display = 'none';
		}
		if($('presets') != null){
			$('presets').style.display = 'none';
		}
		if($('blog') != null){
			$('blog').style.display = 'none';
		}
	}
	if(id == 'presets' && $(id) != null){
		if($(id) != null){
			$(id).style.display = '';
		}
		if($('products') != null){
			$('products').style.display = 'none';
		}
		if($('tutorials') != null){
			$('tutorials').style.display = 'none';
		}
		if($('blog') != null){
			$('blog').style.display = 'none';
		}
	}
	if(id == 'blog' && $(id) != null){
		if($(id) != null){
			$(id).style.display = '';
		}
		if($('products') != null){
			$('products').style.display = 'none';
		}
		if($('tutorials') != null){
			$('tutorials').style.display = 'none';
		}
		if($('presets') != null){
			$('presets').style.display = 'none';
		}
	}
	button_on = id;
}