/**
 * @author javidan
 */

jQuery.fn.cSelect = function(){
	var obj=this;
	var initHeight=obj.height();
	var ul=$('ul',obj);
	var li=$('ul li',obj);
	var duration=400;
	var pos = obj.offset()

	var selected=$('.selected',obj);
	
	$(selected).prependTo(ul);
	
	
	var checkParent = function(parent, children){
	 	var ret=true;
		var a= $(parent).find('*').each(function(){
		if (this === children) {
				ret=false;
			}
		});
		return ret;
	 }
		
	$(obj).live('mouseover',function(event){
		
		var a = checkParent(obj,event.relatedTarget)
		pos = obj.offset()
		
		if (a === true) {
			obj.addClass('absolute');
			obj.css({left:pos.left,top:pos.top+5});
			obj.animate({
				height: ul.height()+5
			}, duration)
		}

	 });
	 
	 $(obj).live('mouseout',function(event){
	 	
		var a = checkParent(obj,event.relatedTarget)
		
		if (a === true) {	
			obj.animate({
				height: initHeight
			}, duration,function(){
				obj.removeClass('absolute');
				obj.css({left:null,top:null});
			})
		}
	 })
	 
	 
	 
}


$(document).ready(function(){
	
	
	$('.cSelect').cSelect();
 
	
})
	 
