/**
 * FileName: cms_functions.js
 * Version: 1.0 
 * Creation Date: 2011/04/07 - 04:54
 * Description: This file is used to hold small functions.
 * Author: jcanedo  
 **/

$(document).ready(initiating_events);

function initiating_events() { 

	/**
	 * Function: Menu Lateral
	 * Version: 1.0 
	 * Creation Date: 2011/04/07 - 04:55
	 * Description: Actions and effects to the menu.
	 * Author: jcanedo  
	 **/      

	//open items of the menu that you want to show
	$("#menu div.menu-item h3.close").eq(0).attr("class","open");
	 
	//hidden item's submenus
	$('.menu-item').each(function(){
		var attr_class=$(this).find('h3').attr("class");
		var set_height=$(this).find('.menu-content').height();
		if(attr_class=='close'){
			$(this).find('.menu-overflow').height(0);
			$(this).find('.menu-content').css('marginTop',-set_height);
		}
		//fix jcanedo
		else {
			$("#menu div.menu-item h3.open").find('img').attr('src','/CMS/images/ico-arrowOpen.gif');
		}
		
	});
	
	//function when clicked on the menu item	
	$('.menu-item h3').click(function(){
		var speed=500;
		var set_height=$(this).parent().find('.menu-content').height();
		var attr_class=$(this).attr("class");
		
		if(attr_class=='close'){
			$(this).removeClass('close');
			$(this).addClass('open');
			$(this).parent().find('.menu-overflow').animate({height:set_height+'px'},speed);
			$(this).parent().find('.menu-content').animate({marginTop:'0'},speed);
			$(this).parent().find('.open img').attr('src','/CMS/images/ico-arrowOpen.gif');
		}

		if(attr_class=='open'){
			$(this).removeClass('open');
			$(this).addClass('close');
 			$(this).parent().find('.menu-overflow').animate({height:'0px'},speed);
			$(this).parent().find('.menu-content').animate({marginTop:'-'+set_height},speed);
			$(this).parent().find('.close img').attr('src','/CMS/images/ico-arrowClose.gif');
		}
	});
	
	//move the icons to the right
	$(".menu-content li a").hover(function(){
		$(this).animate({paddingLeft:'25px'},{queue:false,duration:250});
	},function(){
		$(this).animate({paddingLeft:'20px'},{queue:false,duration:250});
	});

	$(".menu-content li a").hover(function(){
		
	});
	
	/**
	 * Function: Table "List"
	 * Version: 1.0 
	 * Creation Date: 2011/04/07 - 08:37
	 * Description: Add backgrounds gray and white to the rows of the table list
	 * Author: jcanedo  
	 **/   						
	if($("table.list").get(0)) {
		$("table.list tr td.item-list").addClass('rowGray');
		$("table.list tr:odd td.item-list").addClass('rowWhite');
		
		//MouseOver and MouseOut to the row of menu item list
		$("td.item-list").mouseover( function() {
			x = $(this).parent();
			x.children().addClass("selected_item_list");
		}), $("td.item-list").mouseout( function() {
			x = $(this).parent();
			x.children().removeClass("selected_item_list");
		});
	}
	
	//when mouseover on the buttons of action
	$("li.btn-navi a").mouseover( function() {
		$(this).parent().css("background","url('/CMS/images/bg-btnOver.gif') no-repeat top left");
		$(this).css("color","#f0f1f2");
	}),$("li.btn-navi a").mouseout( function() {
	      $(this).parent().css("background","url('/CMS/images/bg-btn.gif') no-repeat top left");
		$(this).css("color","#273343");
	});	
	
	//add background to the "actions" buttons and display different the color of the text
	$("div.listmenu ul li a").mouseover( function() {
		$(this).parent().css('background','#f0eeee');
		$(this).children('span').css('color','#000');
	}),$("div.listmenu ul li a").mouseout( function() {
		$(this).parent().css('background','none');
		$(this).children('span').css('color','#5c5c5c');
	});				
}
