// JavaScript Inbox Marketing Solutions S.A. de C.V.

var loadimg=function (val,rest,style,ancho,alto){
	
	$('#'+val).each(function() {
		var $container = $(this);
		
		$container.empty()
		          .css('width',$container.width());
	
		$.get('xml/'+val+'.xml', function(data) {    		
	
				var count='';
				$(val.substr(val,val.length-rest), data).each(function() {
							count++;		 
							var $link;		 
							/* = $('<img/>')		
													.attr('src','img/elementos/'+val+'/'+ $('name', this).text())
													.attr({
															'id': val+count,
															'width': ancho,
															'height':alto															
														});
													*/
													
													
					        if($('urllink', this).text())
							{		
									
											$link = $('<a></a>').append($link)
											
													.attr({
														   'href':$('urllink', this).text(),
														   'title':$('urllink', this).text(),
														   
														 })
													.css('border',"none")
													.css({
															'background':'url(img/elementos/'+val+'/'+ $('name', this).text()+')',
															'width': ancho,
															'height':alto,
															'background-position':'top'
															})
													.addClass('logos');
											 if($('urllink', this).text()!='#')
											 {
												 	$link.attr('target',$('urllink', this).text());
											 }	
													
													
							}
													
							var $headline = $('<li></li>').append($link)
     													  .addClass(style)
														  .appendTo($container);
											
											
				 });
			
/*			$('li > img').mousedown(
						 function (e)
						 {   
												
					var $enlargedCover = $('<div><p>[CERRAR]</p></div>')
				
					.attr('id',"modal")
					.appendTo('body');
					
					var $logo = $('<img/>')
					.attr('id',"imgCover")
					.attr('src',$(this).attr('alt'))
					.addClass('enlarged')
					.appendTo($enlargedCover);
					
					$enlargedCover
					.css({
							'top' : 0,
							'width': 1024,
							'height': 800
					}).show()
					
					.one('click', function() {
										   
						$enlargedCover.fadeOut();
						
					});
																	
			});*/
	
		 });
	


	});
	
	
};


function rotar(val,style)
{
	$('#'+val).each(function() {
							 
	var $container = $(this);
		$container.css('width',($('li.'+style).length)*$('li.'+style).width());
				
				var currentHeadline = 0, oldHeadline = 0;
				var hiddenPosition = $container.width();
				var elementWidth =$('li.'+style).width(); 
				//$('li.'+style).eq(currentHeadline).css('left', 0);
				var headlineCount = $('li.'+style).length;
				
				var pause;
				var rotateInProgress = false;
		
					var headlineRotate = function() {
						
						
							currentHeadline = (oldHeadline + 1) % headlineCount;
							
								/*$('li.'+style).animate(
													{left: -hiddenPosition}, 2000, function() {
													$(this).css('left', hiddenPosition); //$(this).css('left', hiddenPosition+40);
										});*/
								
								  $('li.'+style).animate(   {left: -(elementWidth*2)}, 10000, function() {
									 				$('li.'+style).clearQueue();
  													$('li.'+style).stop();	
																			  $('li.'+style+':first').insertAfter($('li.'+style+':last'));
																			  $('li.'+style).css('left',-150);	
																			 		  
																			  //$('li.'+style+':first a').attr('title');
																			  
																			  headlineRotate();
								  },false,false);
		
																			
						  
					};
		
					headlineRotate();
					
					$container.hover(function() {
													
													pause = false;
													
													$('li.'+style).clearQueue();
  													$('li.'+style).stop();	
					
												}, function() {
																rotateInProgress = false;	
																				headlineRotate();	
															  });
					$('li.'+style+' a').hover(function() { 
															$(this).css('background-position','bottom');
														  },function(){$(this).css('background-position','top');}
														  );
							 
		});

};


/*$(document).ready(function() {

		var setDos=loadimg('promociones',2,'headprom',563,326);			   

		setTimeout("new rotar('promociones','headprom')",600);
		
});
*/
// JavaScript Inbox Marketing Solutions S.A. de C.V.
