/*
 * CustomJS - custom written JavaScripts with famous :P
 * Needs jQuery 
 * */



$.noConflict();



var CustomJS = {

	revalForms : function ( parent ) {

		if( typeof parent === "string" ) {

			parent = document.getElementById(parent);

		}

		var children = parent.childNodes;

		for( var i = 0 ; i < children.length ; ++i ) {

			var t = children[i];

			if( (t.nodeName.toLowerCase() == "input" && t.type.toLowerCase() == "text") || t.nodeName.toLowerCase() == "textarea" ) {

				t.backup = t.value;

				t.onfocus = function(){ if( this.value == this.backup) this.value = ''; }

				t.onblur = function() { if( this.value == '' ) this.value = this.backup; }

			}

			arguments.callee(t);

		}

	},

	rotateSpriteBaners : function (holder_id, path, step, num, interval) {

		// for now path is not used



		var backHolder = jQuery("#"+holder_id);				 // div with bg

		var foreHolder = jQuery("#"+holder_id+ " img");		// this is a img tag

		var cstate = step;



		function rot() {

			

			var nstate = (cstate+step) % (num*step);

			backHolder.css('backgroundPosition', "0px -" + nstate + "px");

			foreHolder.fadeOut(1500, function(){

				cstate = nstate;

				foreHolder.css('top', "-" + cstate + "px");

				foreHolder.show();

			});

		}



		setInterval(rot, interval);

	},

	expanded : null,
	inAnimation : false,

	initCategoryExpanders : function(parent) {

		if( ! parent ) {

			return;

		}

		var children = parent.childNodes;

		for(var i = 0, len = children.length ; i < len ; ++i ) {

			if( children[i].nodeType === 1 && children[i].className === 'children' ) {

				jQuery(parent).bind('mouseover', function() {
					
					if (!CustomJS.inAnimation) {
						CustomJS.inAnimation = true;
						
						if (CustomJS.expanded === this) {
							CustomJS.inAnimation = false;
							return;
						}
						
						
						if (CustomJS.expanded) {
							jQuery("ul.children", CustomJS.expanded).slideUp(400, function () {});							
						}
						jQuery("ul.children", this).slideDown(400, function () {
							CustomJS.inAnimation = false;
						});
						CustomJS.expanded = this;
					} 
					
				})

			}

			arguments.callee(children[i]);

		}

	}

}



jQuery(function() {

	CustomJS.revalForms(document.body);

	CustomJS.rotateSpriteBaners("rotator", "/img/banners/sp.jpg", 203, 5, 7000);

	CustomJS.initCategoryExpanders(document.getElementById("category-list"));

});




