YAHOO.namespace("jsGenutil");
/* switch the select class property of an element */
YAHOO.jsGenutil.switchSelected = function (id) {
	YAHOO.jsGenutil.switchActive(id,'selected','a');
}
YAHOO.jsGenutil.switchSelectedLi = function (id) {
	YAHOO.jsGenutil.switchActive(id,'current','li');
}
/*
 switch the select class property of an element
 id - the ID of the element
 selectedclassval - the class value to use eg active, selected ...
 elm - the tag name of the element eg div, a , li ..
  used by switchSelected function above
*/
YAHOO.jsGenutil.switchActive = function (id, selectedclassval,elm) {
	var DOM = YAHOO.util.Dom;
	
	var par = DOM.getAncestorByClassName(id,'ilights');
	var el = DOM.getElementsByClassName(selectedclassval,elm,par);
	if(el.length > 0)
	{
		DOM.removeClass(el[0].id, selectedclassval);
	}
    DOM.addClass(id, selectedclassval);
}

YAHOO.jsGenutil.suckerfish = function (type, tag, parentId) {

YAHOO.util.Event.onContentReady(parentId, function () { 

	if (window.attachEvent) {

		//window.attachEvent("onload", function() {
			var sfEls = (parentId==null)?document.getElementsByTagName(tag):document.getElementById(parentId).getElementsByTagName(tag);
			if(type == 'sfHover'){
				YAHOO.jsGenutil.sfHover(sfEls);
			}

//		});
	}

	}); 

}

YAHOO.jsGenutil.sfHover = function(sfEls) {
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
/* call watermark function to put label in textbox */
YAHOO.jsGenutil.overlabel = function(){
	setTimeout(initOverLabelss, 50);
}
YAHOO.jsGenutil.switchinfo = function(infochild_id, parent_id){
	var DOM = YAHOO.util.Dom;
	var e = YAHOO.util.Event;
	if(YAHOO.util.Dom.get(infochild_id)){
			e.onContentReady(parent_id,function(){
			 var numchild =YAHOO.util.Dom.getChildren(parent_id).length;
			if(numchild > 4){
				DOM.get(infochild_id).style.display = 'none';
			}else{
				DOM.get(infochild_id).style.display = 'block';
			}
			});
			
			

	}
}
YAHOO.jsGenutil.toggle = function(id,class_id,class_1,class_2,withclass){
	var DOM = YAHOO.util.Dom;
	var curclass = class_2;
	var remclass = class_1;
	if(withclass){
		el = document.getElementById(class_id);
		if(DOM.hasClass(class_id, class_2)){
			curclass = class_1;
			remclass = class_2;
		}
		DOM.removeClass(class_id,  remclass);
		DOM.addClass(class_id,  curclass);
	}
	el = document.getElementById(id); el.style.display = el.style.display == 'none' ? 'block' : 'none';	
}

YAHOO.jsGenutil.showOneHideOtherBlock = function(blockA_id,blockB_id){
	YAHOO.jsGenutil.toggle(blockA_id);
	YAHOO.jsGenutil.toggle(blockB_id);
}
/*
 * create a carousel with the summary auto-highlighted
 * subscribe to "pageChange" event which handles highlight of summary
 * INPUT - containerId - the id of the main carousel
 *       - forCarouselContainerId - the id of the sumary container
 *       - autoPlayInterval - how long a page should be displayed
 *       - classname  - the highlight class
 * */
YAHOO.jsGenutil.carousel = function(containerId,forCarouselContainerId,autoPlayInterval,classname){
    var carousel = new YAHOO.widget.Carousel(containerId,{ autoPlayInterval: autoPlayInterval, isCircular: true, numVisible: 1 });
    carousel.on("pageChange", function (index) { 
    	var DOM = YAHOO.util.Dom;
	    var par = document.getElementById(forCarouselContainerId);//get the parent
	    var children = par.getElementsByClassName('item','li'); //get the children
	    var omit = 1; //number of pages to omit
	    var ind = index - omit; //new index for summary 
	    var prevind = ind -1;//previous index
	    /*
	     * check if we are in display pages area, highlight
	     * otherwise remove highlight
	     * */
	    if(ind >=0 ){
		    if(prevind < 0){
			    prevind = children.length - 1 - omit;
		    }
		    DOM.removeClass(children[prevind].getAttribute('id'), classname);
		    DOM.addClass(children[ind].getAttribute('id'), classname);
	    }else{
	    	DOM.removeClass(children[children.length - 1].getAttribute('id'), classname);
	    }
    		  }); 
    carousel.render(); // get ready to render the widget
    carousel.show();   // display the widget
    carousel.startAutoPlay();	
}
/*
YAHOO.jsGenutil.modalcarousel = function(containerId,autoPlayInterval){
    var carousel = new YAHOO.widget.Carousel(containerId,{ autoPlayInterval: autoPlayInterval, isCircular: true, numVisible: 1 ,modal: true, visible: false});
    carousel.render(); // get ready to render the widget
    carousel.show();   // display the widget
    carousel.startAutoPlay();	
}
*/
YAHOO.jsGenutil.Carousels = function(){
	var mpanel = null;
	var normalcarouselhandle = null;
	var ismodal = false;
	var navbar = null;
	var DOM = YAHOO.util.Dom;
	var par_id = '';
	var par_height = '1px';
	
	var modalcarousel = function(id,width,height){
		document.getElementById(id).style.display='block';
		
		mpanel = new YAHOO.widget.Panel(id,  
                {  
    				width: width+'px',
    				height: height+'px',
                    fixedcenter: true, 
                    close: false, 
                    draggable: true, 
                    zindex: 5,
                    modal: true,
                    visible: false
                } 
            );

    //	overlay.setHeader("tttttttt");
	//this.overlay.setBody(document.getElementById(id).innerHTML);
		mpanel.render();
		//if(anchor != ''){
		//	mpanel.cfg.setProperty('context',[anchor, 'tl', 'br']);
		//}else{
		//	mpanel.cfg.setProperty('fixedcenter',true);
		//}		
    	//overlay.show();	
	};
	var normalCarousel = function(containerId,autoPlayInterval,animate){
		normalcarouselhandle = new YAHOO.widget.Carousel(containerId,
				{ autoPlayInterval: autoPlayInterval,
				  isCircular: true, 
				  numVisible: 1 ,
				  visible: false
				  });
		if(animate){
			normalcarouselhandle.set("animation", { speed: 0.2 });
		}
		
		normalcarouselhandle.render(); // get ready to render the widget
		//normalcarouselhandle.show();   // display the widget
		//normalcarouselhandle.startAutoPlay();
		var el = DOM.getElementsByClassName('yui-carousel-nav','div',containerId);
		if(el.length >0){
			navbar = el[0];
			navbar.style.display = 'none';
		}
	};	
	return {
		init: function(containerId,autoPlayInterval,parentid,parwidth,parheight,animate,makemodal){
		
		normalCarousel(containerId,autoPlayInterval,animate);
			
			if(makemodal){
			
				modalcarousel(parentid,parwidth,parheight);
				//document.getElementById(parentid+'_c').style.height = '1px';
				document.getElementById(parentid+'_c').style.position ='';
			}else{
				normalcarouselhandle.show();   // display the widget
				normalcarouselhandle.startAutoPlay();
			}
			par_id = parentid;
			par_height = parheight;
		},
	    show: function () {
			if(mpanel){
				//document.getElementById(par_id+'_c').style.height = par_height+'px';
				//document.getElementById(par_id+'_c').style.position ='';
				mpanel.show();
			}
		/*	if(DOM.get(par_id).style.left == '-1000px'){
				DOM.get(par_id).style.left = '0px';
				DOM.get(par_id).style.top = '0px';
			}
		*/	
			normalcarouselhandle.show();   // display the widget
			if(navbar){
				navbar.style.display = 'block';
			}
			normalcarouselhandle.startAutoPlay();				
        },
        hide: function(){
        	normalcarouselhandle.stopAutoPlay(); 
        	normalcarouselhandle.hide();   // display the widget
			       	
			if(mpanel){
				mpanel.hide();	
			}
			if(navbar){
				navbar.style.display = 'none';
			}
        }   		
	}
}();

YAHOO.jsGenutil.hasClassName = function(el, name){
	var re = new RegExp('(^| )' + name + '( |$)');
	if(re.test(el.className)){
		return true;
	}
	return false;
}

YAHOO.jsGenutil.showOneOfMany = function(id,tagname,classtype,parid){
	var Dom = YAHOO.util.Dom; 
	var JT = YAHOO.jsGenutil;
	var chkboxs = Dom.getElementsBy(function(el){return(YAHOO.jsGenutil.hasClassName(el,classtype) && el.style.display == 'block');},tagname,parid, function(el){el.style.display = 'none';});	
//alert("n "+chkboxs.length+" tn "+tagname+' cn '+classtype+' pi '+parid+' id ');
	Dom.get(id).style.display = 'block';
}
//==================================================
/**
 * event watching function
 * usage var obj = new watchThis(id, customprop, callback);
 * 			 obj.addClickHandler();
 */
function watchThis(elementId, customProp, callback){
	this.elementId = elementId;
	this.customProp = customProp;
	this.callback = callback;
}
watchThis.prototype.addClickHandler = function() {
	   YAHOO.util.Event.addListener(this.elementId, "click", this.callback, this);
	};
	 
watchThis.prototype.addKeyHandler = function() {
	   YAHOO.util.Event.addListener(this.elementId, this.customProp, this.callback, this);
	};
//=================================================
/*
 * 
 */
function clickedOutsideThisBox( clickTarget,box_id) {
	var node = $(box_id);
    return clickTarget !== node && !YAHOO.util.Dom.getAncestorBy(clickTarget,
        function ( parent ) {
            return parent === node;
        });
}
//=================================================
function loginBoxClosingHandler(e){
	var src = YAHOO.util.Event.getTarget(e);
    if( src.id != 'dropdown_menu' && clickedOutsideThisBox(src,'login_box') && YAHOO.util.Dom.getStyle('login_box', 'display') == 'block'){
    	YAHOO.jsGenutil.toggle('login_box','dropdown_menu','login_sign','login_dropped',true);
    }
}
//=======================================