// JavaScript Document
function fetchXMLData(dataUrl)
{  
	var returnArray					= Array();
	var dataConfig 					= {};
	var flashImagesArray 		= Array();
	var date 								= new Date();
	dataUrl 								+= "?"+date.getTime();
	$.ajax({
        type: "GET",
				url: dataUrl,
				dataType: "xml",
				async: false,
				success: function(xml) 
				{    
				 		/* ==================================== master configuration ==================================== */
						$(xml).find('config').each(function()
						{  
		 					dataConfig = 
		 						({
										backgroundColor:$(this).attr('backgroundColor') || "#FFFFFF",
										bannerWidth:parseInt($(this).attr('bannerWidth')),
										bannerHeight:parseInt($(this).attr('bannerHeight')),
										imageWidth:parseInt($(this).attr('imageWidth')) || parseInt($(this).attr('bannerWidth')),
										imageHeight:parseInt($(this).attr('imageHeight')) || parseInt($(this).attr('bannerHeight')),
										delay:parseInt($(this).attr('delay')) || 1000,
										effect:parseInt($(this).attr('effect')) || 0,
										transparent:$(this).attr('transparent') || "false"
		 							});
						});
					 returnArray[0]													= dataConfig;
					 /* ==================================== text,image configuration ==================================== */
					 var counter					 = 0;
					 $(xml).find('banner').each(function(){
					 	  flashImagesArray[counter] = Array();
					 		flashImagesArray[counter]['url'] 		= $(this).find('image').attr('url')+'?'+date.getTime();
					 		flashImagesArray[counter]['effect'] = parseInt($(this).find('image').attr('effect'));
					 		//if(!flashImagesArray[counter]['effect'] >= 0 || flashImagesArray[counter]['effect'] < 0)
					 		if(isNaN(flashImagesArray[counter]['effect']))
					 		{
					 			flashImagesArray[counter]['effect'] =  dataConfig.effect;
					 		}
					 		flashImagesArray[counter]['delay'] 	= parseInt($(this).find('image').attr('delay')) || dataConfig.delay;
					 		flashImagesArray[counter]['aHref']  = $(this).find('link').attr('url') || "";
					 		flashImagesArray[counter]['aTarget']= $(this).find('link').attr('target')  || "";
					 		flashImagesArray[counter]['aTitle'] = $(this).find('link').attr('title') || "";
							flashImagesArray[counter]['text'] = Array();
					 		var textCounter = 0;
					 		$(this).find('text').each(function(){
					 			flashImagesArray[counter]['text'][textCounter] = Array();
					 			flashImagesArray[counter]['text'][textCounter]['x'] = $(this).attr('x');
					 			flashImagesArray[counter]['text'][textCounter]['y'] = $(this).attr('y');
					 			flashImagesArray[counter]['text'][textCounter]['width'] = $(this).attr('width');
					 			flashImagesArray[counter]['text'][textCounter]['height'] = $(this).attr('height');
					 			flashImagesArray[counter]['text'][textCounter]['direction'] =  $(this).find('start_animation').attr('direction');
					 			flashImagesArray[counter]['text'][textCounter]['time'] = $(this).find('start_animation').attr('time') * 1000;
					 			flashImagesArray[counter]['text'][textCounter]['cdata'] = $(this).find('data').text();
					 			textCounter++;
					 		});
					 		counter++;
					});
					returnArray[1]				= flashImagesArray;
			  }
		});
		return returnArray;
}


jQuery(function($){

$.fn.banner = function(options){
/* ================================================================================================ */
/* ======================================== dynamic variables ===================================== */
/* ================================================================================================ */	
 	var dataConfig1 = {};
	var flashImagesArray = Array();
 	var args = arguments[0] || {}; // It's your object of arguments
 	var date = new Date();
 	if (typeof current_banner_xml_file == 'undefined')
 	{
 		current_banner_xml_file  =		"data/data.xml";
 	}
 	var dataUrl = current_banner_xml_file || "data/data.xml";
  dataUrl += "?"+date.getTime();
	var mode		= args.mode || "banner";

/* ================================================================================================ */
/* ======================================== Plugin Options ======================================== */
/* ================================================================================================ */	

	var defaults = {
						bannerSlug: 'banner_',
						backgroundColor: "#FFFFFF",
		        delay:100,
					  bannerWidth:702,
					  bannerHeight:342,
					  imageWidth:702,
					  imageHeight:342,
					  effect:2,
					  transparent:false,
					  autoplay:true,
					  playCount:0,
					  blocksize: {height:'',width:'' },
					  maskInduration:300,
					  maskOutduration:900,
					  cubegrowDuration:900,
					  stripfadeDuration:700,
					  stripHalfDuration:700,
						curtainsrightDuration:900,
						waveleftDuration: 700,
						blindsleftDuration: 700,
						fadeinDuration: 1500,
						MaskverticalDuration: 700,
					  listControls:true,
					  arrowControls:true,
					  customblocksize:{
						  maskvertical:{ height:100,width:70 },
						  // image transitions global settings
						  cubegrow:{ height:130,width:130 },
						  cubesidegrow:{ height:130,width:130 },
						  stripfade:{ height:100,width:60 },
						  striphalf:{ height:100,width:40 },
						  block:80,
						  strip:30
						  
						  },
					  callback:function(){   } 
					  
					  
					};
	
		/* ================================================================================================ */
	/* ==================================== Fetching Data.xml to get banner configuration ============= */
	/* ================================================================================================ */	

	 if(mode == "play")
	 {
			dataConfig1																			= tempPlayPreviewConfig;
			dataConfig1['transparent'] 											= false;
			flashImagesArray[0]															= new Array();
			flashImagesArray[0]															= editFlashImagesArray[activeLanguageID][currentSlideNo];
		}
		else if(mode == "preview")
		{
			dataConfig1																			= dataConfig[activeLanguageID];
			flashImagesArray																= editFlashImagesArray[activeLanguageID];
		}
		else
		{
			var xmlData 																		= fetchXMLData(dataUrl);
			dataConfig1																			= xmlData[0];
			flashImagesArray																= xmlData[1];

		}
			
	var options = $.extend(defaults, options, dataConfig1);
	if(navigator.userAgent.match(/iPad/i) != null)
	{
		options.cubegrowDuration												= options.cubegrowDuration 					- 700;
		options.stripfadeDuration 											= options.stripfadeDuration 				- 500;
		options.stripHalfDuration 											= options.stripHalfDuration 				- 400;
		options.curtainsrightDuration										= options.curtainsrightDuration 		- 700;
	}

/* ================================================================================================ */
/* ==================================== Variables & Precaching ==================================== */
/* ================================================================================================ */	
	
	return this.each(function()
		{	 
		var root = $(this).addClass('banner-img banner-inner-img');
		var tempId = date.getTime();
		options.tempId  = tempId;
		root.wrap('<div class="banner-img-wrapper" id="'+tempId+'"/>');
		var wrapperDiv = 	root.parent();
		//alert(wrapperDiv.html());
		var parent = root.parent();
		parent.append("<span class='bannerLoader'></span>");
		/* ==================================== adding image and text span for slider ==================================== */
		if(flashImagesArray.length > 0)
		for(var i = 0; i < flashImagesArray.length; i++)
		{
			var imgLinkStartTag			= '';
			var imgLinkEndTag				= '';
		  var activeClass = ((i == 0) ? "active" : "deactive"); 
		  
		  /* ============= if link to image exist ========================= */
		  if(flashImagesArray[i]['aHref'] != '')
		  { 
		  	imgLinkStartTag				= "<a href='"+flashImagesArray[i]['aHref']+"'  target='"+flashImagesArray[i]['aTarget']+"' title='"+flashImagesArray[i]['aTitle']+"'>";
		  	imgLinkEndTag					= "</a>";
		  } 
		  
		  /* ============= if link to image exist ========================= */
		  
			$(this).append('<li cust="'+options.bannerSlug+'imageHolder_'+i+'" class="deactive" >'+imgLinkStartTag+'<img src="'+flashImagesArray[i]['url']+'" alt="" cust="'+i+'"/>'+imgLinkEndTag+'</li>');

		  for(var m  = 0; m < flashImagesArray[i]['text'].length; m++)
		  {
		 	  var elementLeft = options.bannerWidth+'px';
		 	  var extraStyle  = "opacity: 1.0;filter: alpha(opacity = 100);";
		 		if(flashImagesArray[i]['text'][m]['direction'] == 'left')
		 		{
		 			elementLeft  = '-'+flashImagesArray[i]['text'][m]['width']+"px";
		 		}
		 		else if(flashImagesArray[i]['text'][m]['direction'] == 'none')
		 		{
		 			elementLeft  = flashImagesArray[i]['text'][m]['x'];
		 			extraStyle	 = "opacity: 0.0;filter: alpha(opacity = 00);";
		 		} 
		 	 	$(".banner-img-wrapper").append('<span cust="'+options.bannerSlug+i+'_div_'+m+'" class="slide-text" style="width:'+flashImagesArray[i]['text'][m]['width']+'px; height:'+flashImagesArray[i]['text'][m]['height']+'px; left:'+elementLeft+'; top:'+flashImagesArray[i]['text'][m]['y']+';'+extraStyle+'">'+flashImagesArray[i]['text'][m]['cdata']+'</span>');
		  }
		}
		
		var li = root.find("li");
	  var images = li.find("img");
		var pos,random_no,timer,image_timer,counter,arr,wait,index,block,w,h,src,parent,im,override=false,in_animation = false,controls,canvas,html5_flag=false,imageData,canvas,context,root_parent,runBanner = 0;
	  //var current = li.eq(1).toggleClass('active'),prev = li.first().addClass("reset");
		//var current = li.eq(0),prev = li.last().addClass("reset");		
		var current = li.last(0),prev = li.last().addClass("reset");
		root.css({
			width: options.imageWidth,
			height: options.imageHeight
			});	
			
		parent.css({
			width: options.bannerWidth,
			height: options.bannerHeight
			});	
			
		type= "img";
		canvas = document.createElement('canvas');
    if (!canvas.getContext) {
      options.mode= "default";
	  
	   if(!isNaN(options.effect)&&parseInt(options.effect) >= 10)
	   options.effect='none';
	   
    }
	
/* ================================================================================================ */
/* ======================================== Switcher Module ======================================= */
/* ================================================================================================ */			
		function switcher()
			{ 
				if($("#"+options.tempId).length == 0) return false;
				
				prev = (current.prev().length>0) ? current.prev() : li.last();
				prev.removeClass("reset");
				prev.addClass("deactive");
				current.toggleClass("active reset");
				current = (current.next().length>0) ? current.next() : li.first();
				current.find(type).hide();
				current.toggleClass("active deactive");
				options.callback(current.find(type)[0]);
		  
		   }

/* ================================================================================================ */
/* ======================================== Custom Effects ======================================== */
/* ================================================================================================ */	

	function Maskvertical(image)
	{
		in_animation =true;
		 im = image;
		
		
			 if(options.blocksize.width!=''){
		 w = Math.floor(options.blocksize.width);
		 h = Math.floor(options.blocksize.height);
		 }
		 else
		 {
		w = Math.floor(options.customblocksize.maskvertical.width);
		 h = Math.floor(options.customblocksize.maskvertical.height);	 
		 }
		
		 parent = im.parent();
		 arr = new Array(); i =0;  j =0; index = 0;
		 block = $("<div />",{
					css:{
						position:"absolute",
						width:w,
						height:options.bannerHeight,
						'background-color': options.backgroundColor,
						'border':options.maskborder,
						zIndex:99,
						display:'none'
						}
							
							}).addClass('disblock');
		
		
		 while(i<options.imageWidth)
		 {
			
				arr[index] = block.clone().css({left:i ,top:j,backgroundPosition:-i+"px 0px" });
				 parent.append( arr[index++].fadeIn(i*4+4));
			
			i = i + w;
		 }
		 
			var wait = setInterval(function() {
			  if( ! parent.find(".disblock").is(":animated") ) {
				  clearInterval(wait);
			animateout();	
			  }
		  }, 40);
		
		function animateout()
		{
		im.fadeIn(500); 
		i=0;
		random_no = random_array(arr.length);
	    timer = setInterval(function(){
				
				if(i>=arr.length)
				{ 
				
				clearInterval(timer);
				var wait = setInterval(function() {
			      if( ! parent.find(".disblock").is(":animated") ) {
				  clearInterval(wait);
			      endeffect(image);
			        }
		          }, 80);
				return;
				
				}
									 
				
				arr[random_no[i]].stop(true,true).fadeOut({duration:options.MaskverticalDuration,easing:'easeInSine'});
				i++;
				},90);
		
		
		}
	  };
	  
  function striphalf(image)
	{
	in_animation = true;
	w = (options.blocksize.width!='') ? Math.floor(options.blocksize.width) : Math.floor(options.customblocksize.striphalf.width);
	h = options.imageHeight;
	parent = image.parent();
	arr = new Array(); i =0;  j =0;
	src = image.attr("src");
	block = $("<div />",{
		css:{
				position:"absolute",
				width:w,
				height:h/2,
				'background-image':'url('+src+')',
				'background-color':options.maskbg,
				'border':options.maskborder,
				 zIndex:99,
				 display:'block',
				 opacity:0
			}
	}).addClass('disblock');
		
	 counter = 60;
	 while(i<options.imageWidth)
		 {
			j=0;
			while(j<h)
			{
				if(j==0)
				css ={left:i,top:j ,backgroundPosition:-i+"px "+(-j)+"px" ,marginTop: -(h/2)};
				else
				css ={left:i,top:j ,backgroundPosition:-i+"px "+(-j)+"px" ,marginTop: h};
				parent.append(block.clone().css(css).delay(counter).animate({opacity:1,marginTop:0},{duration: options.stripHalfDuration, easing:'easeOutBack'}));
				j = j + h/2;
				counter = counter + 45;
			}
			i = i + w;
		 }
		 
		i=0;
		wait = setInterval(function() {
			  if( ! parent.find(".disblock").is(":animated") ) {
				  clearInterval(wait);
				 endeffect(image);
			  }
		  }, 100);
		
	}
	
	
	function waveleft(image)
	{ 
	in_animation = true;
	w = 16;
	h = options.imageHeight;
	parent = image.parent();
	arr = new Array(); i =0;  j =0;
	src = image.attr("src");
	block = $("<div />",{
		css:{
				position:"absolute",
				width:w,
				height:h,
				'background-image':'url('+src+')',
				'background-color':options.maskbg,
				'border':options.maskborder,
				 zIndex:99,
				 display:'block',
				 opacity:0
			}
	}).addClass('disblock');
		
	 counter = 10;
	 while(i<options.imageWidth)
		 {
				css ={left:i,top:j ,backgroundPosition:-i+"px "+(-j)+"px" ,marginTop: h};
				parent.append(block.clone().css(css).delay(counter).animate({opacity:1,marginTop:0},{duration: options.waveleftDuration, easing:'easeOutBack'}));
				counter = counter + 35;
			
			i = i + w;
		 }
		 
		i=0;
		wait = setInterval(function() {
			  if( ! parent.find(".disblock").is(":animated") ) {
				  clearInterval(wait);
				 endeffect(image);
			  }
		  }, 40);
		
	}
	
	 function cubegrow(image)
	{
		if($("#"+options.tempId).length == 0) return false;
 	  
 	  in_animation = true;
		 im = image;
		if(options.blocksize.width!=''){
		 w = Math.floor(options.blocksize.width);
		 h = Math.floor(options.blocksize.height);
		 }
		 else
		 {
		w = Math.floor(options.customblocksize.cubegrow.width);
		 h = Math.floor(options.customblocksize.cubegrow.height);	 
		 }
		 parent = im.parent();
		 arr = new Array(); i =0;  j =0; index = 0;
		 src = im.attr("src");
		 block = $("<div />",{
					css:{
						position:"absolute",
						width:0,
						height:0,
						'background-image':'url('+src+')',
						'background-color':options.maskbg,
						'border':options.maskborder,
						zIndex:99
						
						}
							
							}).addClass('disblock');
		
		counter = 40;
		 while(i<options.imageWidth)
		 {
			
		    j=0;
			while(j<options.imageHeight)
			{
				
				
				parent.append( block.clone().css({left:i ,top:j,backgroundPosition:-i+"px "+-j+"px" }).delay(counter).animate({height:h,width:w},options.cubegrowDuration));
			j = j + h; counter = counter + 50;
			}
			
			i = i + w;
		 }

		
	  	wait = setInterval(function() {
			  if( ! parent.find(".disblock").is(":animated") ) {
				  clearInterval(wait);
				 endeffect(image);
			  }
		  }, 40);
	};	
	function cubesidegrow(image)
	{
		in_animation =true;
		 im = image;
		if(options.blocksize.width!=''){
		 w = Math.floor(options.blocksize.width);
		 h = Math.floor(options.blocksize.height);
		 }
		 else
		 {
		w = Math.floor(options.customblocksize.cubesidegrow.width);
		 h = Math.floor(options.customblocksize.cubesidegrow.height);	 
		 }
		 parent = im.parent();
		 arr = new Array(); i =0;  j =0; index = 0;
		 src = im.attr("src");
		 block = $("<div />",{
					css:{
						position:"absolute",
						width:0,
						height:0,
						opacity:0,
						top:options.bannerHeight,
						'background-image':'url('+src+')',
						'background-color':options.maskbg,
						'border':options.maskborder,
						zIndex:99
						
						}
							
							}).addClass('disblock');
		
		
		 while(i<options.imageWidth)
		 {
			
		    j=0;
			while(j<options.imageHeight)
			{
				
				arr[index] = block.clone().css({left:i ,top:j,backgroundPosition:-i+"px "+-j+"px" });
				parent.append(arr[index++]);
			j = j + h;
			}
			
			i = i + w;
		 }
		 
		i=0;
		random_no = random_array(arr.length);
	    timer = setInterval(function(){
				
				if(i>=arr.length)
				{
				
				wait = setInterval(function() {
			  if( ! parent.find(".disblock").is(":animated") ) {
				  clearInterval(wait);
				 endeffect(image);
			  }
		  }, 40);
		  
					
				
				 clearInterval(timer);
					return;
				}
									 
				arr[random_no[i++]].animate({height:h,width:w,opacity:1}, options.cubegrowDuration);
				
				},60);
		
	};	
	
	function randombricks(image)
	{
		in_animation =true;
	 im = image;
		if(options.blocksize.width!=''){
		 	w = Math.floor(options.blocksize.width);
		 	h = Math.floor(options.blocksize.height);
		 }
		 else
		 {
		 	w = Math.floor(options.customblocksize.block);
		 	h = Math.floor(options.customblocksize.block);	 
		 }
		 parent = im.parent();
		 arr = new Array(); i =0;  j =0; index = 0;
		 src = im.attr("src");
		 block = $("<div />",{
					css:{
						position:"absolute",
						width:w,
						height:h,
						opacity:0,
						top:options.bannerHeight,
						'background-image':'url('+src+')',
						'background-color':options.maskbg,
						'border':options.maskborder,
						zIndex:99
						
						}
							
							}).addClass('disblock');
		
		
		 while(i<options.imageWidth)
		 {
			
		    j=0;
			while(j<options.imageHeight)
			{
				
				arr[index] = block.clone().css({left:i ,top:j,backgroundPosition:-i+"px "+-j+"px" });
				parent.append(arr[index++]);
			j = j + h;
			}
			
			i = i + w;
		 }
		 
		i=0;
		random_no = random_array(arr.length);
	    timer = setInterval(function(){
				
				if(i>=arr.length)
				{
				wait = setInterval(function() {
			  if( ! parent.find(".disblock").is(":animated") ) {
				  clearInterval(wait);
				 endeffect(image);
			  }
		  }, 80);	
				 clearInterval(timer);
					return;
				}
									 
				arr[random_no[i++]].animate({opacity:1},{duration:500, easing:'easeOutCubic'});
				
				},30);
	};
	
	function curtainsright(image)
	{
		in_animation = true;
		if(options.blocksize.width!='')
		w = Math.floor(options.blocksize.width);
		else
		w = Math.floor(options.customblocksize.stripfade.width);
		
		h = options.imageHeight;
		 parent = image.parent();
		 i = options.bannerWidth; 
		 src = image.attr("src");
		 var css,flag=true;
		 block = $("<div />",{
					css:{
						position:"absolute",
						width:w,
						height:h,
						'background-image':'url('+src+')',
						'background-color':options.maskbg,
						'border':options.maskborder,
						zIndex:99,
						marginTop:options.imageHeight,
						opacity:0
						}
							
							}).addClass('disblock');
		
		counter = 0;
		 while(i>-w)
		 {
			
			
				css = {left:i ,backgroundPosition:-i+"px 0px",marginTop:-options.imageHeight };
				flag = true;
			
			
			parent.append(block.clone().css(css).delay(counter).animate({marginTop:0,opacity:1},options.curtainsrightDuration));
			
			i = i - w; counter = counter + 60;
		 }
		 
		
			wait = setInterval(function() {
			  if( ! parent.find(".disblock").is(":animated") ) {
				  clearInterval(wait);
				 endeffect(image);
			  }
		  }, 40);
	};
	function stripfade(image)
	{
		in_animation = true;
		if(options.blocksize.width!='')
		w = Math.floor(options.blocksize.width);
		else
		w = Math.floor(options.customblocksize.stripfade.width);
		
		h = options.bannerHeight;
		
		
		 parent = image.parent();
		 arr = new Array(); i =0;  j =0; index = 0;
		 src = image.attr("src");
		 block = $("<div />",{
					css:{
						position:"absolute",
						width:w,
						height:h,
						'background-image':'url('+src+')',
						'background-color':options.maskbg,
						'border':options.maskborder,
						zIndex:99,
						opacity:0
						
						}
							
							}).addClass('disblock');
		
		counter = 0;
		 while(i<options.imageWidth)
		 {
		parent.append(block.clone().css({left:i ,backgroundPosition:-i+"px 0px" }).delay(counter).animate({opacity:1},{duration: options.stripfadeDuration, easing:'easeOutSine'}));
			
			i = i + w;counter = counter + 50;
		 }
		 
		i=0;
			var wait = setInterval(function() {
			  if( ! parent.find(".disblock").is(":animated") ) {
				  clearInterval(wait);
				endeffect(image);
			  }
		  }, 40);
		
	};	
	function blindsleft(image)
	{
		in_animation = true;
		if(options.blocksize.width!='')
		w = Math.floor(options.blocksize.width);
		else
		w = Math.floor(options.customblocksize.strip);
		
		h = options.imageHeight;
		
		
		 parent = image.parent();
		 arr = new Array(); i =0;  j =0; index = 0;
		 src = image.attr("src");
		 block = $("<div />",{
					css:{
						position:"absolute",
						width:0,
						height:h,
						'background-image':'url('+src+')',
						'background-color':options.maskbg,
						'border':options.maskborder,
						zIndex:99,
						opacity:0
						
						}
							
							}).addClass('disblock');
		
		counter = 0;
		 while(i<options.imageWidth)
		 {
		parent.append(block.clone().css({left:i ,backgroundPosition:-i+"px 0px" }).delay(counter).animate({width:w,opacity:1},{duration: options.blindsleftDuration, easing:'easeOutSine'}));
			
			i = i + w;counter = counter + 50;
		 }
		 
		i=0;
			var wait = setInterval(function() {
			  if( ! parent.find(".disblock").is(":animated") ) {
				  clearInterval(wait);
				endeffect(image);
			  }
		  }, 40);
		
	};	
	
	
/* ================================================================================================ */
/* ================================= Effects Switching & Ending =================================== */
/* ================================================================================================ */		
	
	function endeffect(image)
	{
		if($("#"+options.tempId).length == 0) return false;
		
		clearInterval(timer);
		setTimeout(function(){
				  image.show(); // show the real image
				  parent.find(".disblock").remove(); // remove the divs
				 
				  in_animation = false;
				  
				  if(override==false) // Return if manually triggered
				   //	image_timer = setTimeout(function() {  /*current.find("span").fadeOut('fast');*/    switcher(); effects();  },(options.delay-800)); 
				  text_execute_animation(image);
			  },1000);
				  
						
	};

	function text_execute_animation (image)
  { 
  	if($("#"+options.tempId).length == 0) return false; 
  	
  	var currentIimage = image.attr('cust')
  	var stringToExecute	= "";
  	var closingString		= "image_timer = setTimeout(function() {switcher(); effects();  },("+eval(flashImagesArray[currentIimage]['delay']-800)+"));";
  	
  	options.playCount++;
  	if(mode == "play" && options.playCount == 1)
  	{
  		 closingString		= "image_timer = setTimeout(function() {call_stop_play();  },("+eval(flashImagesArray[currentIimage]['delay']-800)+"));";
  		 
  	}
  	

  	if(flashImagesArray[currentIimage]['text'].length > 0)
  	{
				var tempSortOrder = [];
				var cnt						= 0;
				for(var textKey in flashImagesArray[currentIimage]['text'])
				{
					tempSortOrder[cnt++] = {key: textKey, textY: flashImagesArray[currentIimage]['text'][textKey]['y']};
				}
				
				tempSortOrder.sort(function(a, b){
					var tempBY = b.textY;
					var tempAY = a.textY;
					tempAY		 = parseFloat(tempAY.replace("%", ""));
					tempBY		 = parseFloat(tempBY.replace("%", ""));
					return tempAY - tempBY;
				});

				
  			//for(var textKey in flashImagesArray[currentIimage]['text'])
  			for(var tempKey in tempSortOrder)
  			{
  				var textKey		= tempSortOrder[tempKey]['key'];
  				var textAnimationTime = flashImagesArray[currentIimage]['text'][textKey]['time'];
  				var aniArgs = {};
  				aniArgs['left'] = flashImagesArray[currentIimage]['text'][textKey]['x'];
  				aniArgs['opacity'] = "1.0";
  				aniArgs['filter'] = "alpha(opacity = 100)";
  				var x = flashImagesArray[currentIimage]['text'][textKey]['x'];
  				stringToExecute	+= "wrapperDiv.find('span[cust=\""+options.bannerSlug+currentIimage+"_div_"+textKey+"\"]').animate({left: '"+x+"', opacity: '1.0', filter: 'alpha(opacity = 100)'}, "+textAnimationTime+", function(){";
  				closingString		+= "});";
  			}
		}
		var newString		= stringToExecute +"  "+ closingString;
		eval(newString);
  };

/*	function text_execute_animation (image)
  { 
 		if($('#'+wrapperDiv.attr('id')).length == 0)
 		{
 			return false;
 		}
  	var currentIimage = image.attr('cust')
  	if(flashImagesArray[currentIimage]['text'].length == 2)
  	{
  			var textAnimationTime = flashImagesArray[currentIimage]['text']['0']['time'];
  			var textAnimationTime1 = flashImagesArray[currentIimage]['text']['1']['time']
  			var aniArgs = {};
  			aniArgs['left'] = flashImagesArray[currentIimage]['text']['0']['x'];
  			aniArgs['opacity'] = "1.0";
  			aniArgs['filter'] = "alpha(opacity = 100)";
  			var aniArgs1 = {};
  			aniArgs1['left'] = flashImagesArray[currentIimage]['text']['1']['x'];
  			aniArgs1['opacity'] = "1.0";
  			aniArgs1['filter'] = "alpha(opacity = 100)";
  			$('#banner_'+currentIimage+'_div_0').animate(aniArgs, textAnimationTime, function(){
					$("#banner_"+currentIimage+"_div_1").animate(aniArgs1, textAnimationTime1, function(){ 
							image_timer = setTimeout(function() { switcher(); effects();  },(options.delay-800));		
					});
				});
		}
		else if(flashImagesArray[currentIimage]['text'].length == 1) 
		{
				var textAnimationTime = flashImagesArray[currentIimage]['text']['0']['time'];
  			var aniArgs = {};
  			aniArgs['left'] = flashImagesArray[currentIimage]['text']['0']['x'];
 				aniArgs['opacity'] = "1.0";
 				aniArgs['filter'] = "alpha(opacity = 100)";
		  	$('#banner_'+currentIimage+'_div_0').animate(aniArgs, textAnimationTime, function(){ 
							image_timer = setTimeout(function() { switcher(); effects();  },(options.delay-800));		
				});
			
		}
		else if(flashImagesArray[currentIimage]['text'].length == 0)
		{
			 image_timer = setTimeout(function() {switcher(); effects();  },(options.delay-800));	
		} 
  };
*/
	
	function remove_text_div()
  {
    /*if($('#'+wrapperDiv.attr('id')).length == 0)
 		{
 			return false;
 		} */

  	var prev = (current.prev().length>0) ? current.prev() : li.last();
  	var prevIimage =prev.find(type).attr('cust');
  	
  	for(var i = 0; i < flashImagesArray[prevIimage]['text'].length; i++)
  	{
  		var elementLeft = options.bannerWidth+'px';
		  if(flashImagesArray[prevIimage]['text'][i]['direction'] == 'left')
			{
				elementLeft  = '-'+flashImagesArray[prevIimage]['text'][i]['width']+"px";
			}
			if(flashImagesArray[prevIimage]['text'][i]['direction'] == 'none')
			{
				//$('#banner_'+prevIimage+'_div_'+i).css({opacity: '0.0'});
				wrapperDiv.find('span[cust="'+options.bannerSlug+prevIimage+'_div_'+i+'"]').css({opacity: '0.0'});
				continue;
			}
  	  //$('#banner_'+prevIimage+'_div_'+i).css({left: elementLeft});
  	  wrapperDiv.find('span[cust="'+options.bannerSlug+prevIimage+'_div_'+i+'"]').css({left: elementLeft});
   	}
 }	

	
	function effects()
	{
		if(wrapperDiv.length == 0) return false;

		 if(root.find(".disblock").is(":animated"))
		 return;
		 
		var ch = Math.floor(Math.random()* 10);
		
		if(!isNaN(options.effect))
		 //ch = options.effect;
			ch = flashImagesArray[current.find(type).attr('cust')]['effect'];

		if(options.transparent == "true")
		{
			prev = (current.prev().length>0) ? current.prev() : li.last();
			prev.addClass("deactive");
		}
		
		if(mode == 'play' || mode == 'preview') ch = parseInt(ch);
		switch(ch)
		 {
				 case 0:	
				 					$(current.find(type)).fadeIn(options.fadeinDuration,function(){
					 						endeffect($(this));
					 				});
					 				break;
				 case 1:  cubegrow(current.find(type));break;
				 case 2:  stripfade(current.find(type));break;
				 case 3:  striphalf(current.find(type));break;
				 case 4:  cubesidegrow(current.find(type));break;
				 case 5:  curtainsright(current.find(type));break;
				 case 6:  randombricks(current.find(type));break;
				 case 7:  waveleft(current.find(type));break;
				 case 8:  blindsleft(current.find(type));break;
				 case 9:  Maskvertical(current.find(type));break;
				 default: 
				 					$(current.find(type)).fadeIn(options.fadeinDuration,function(){
					 						endeffect($(this));
					 				});
					 				break;
		 }
		 remove_text_div();
	}
			
			$(this).find('li[cust="'+options.bannerSlug+'imageHolder_0"] img').load(function()
			{  
					$('.bannerLoader').hide();
					//current.removeClass('deactive');
					current.addClass('active');
					/*root.find('li').each(function()
					{
   						$(this).removeClass('deactive');
  				}); */
					//if(options.autoplay==true)
			 		 	//text_execute_animation(images); 
			 		 	switcher(); effects();
			});
	});

};

function random_array(maxn)
 {
	
    var array = new Array();
	var temp,i,flag=true;
	var index =0;
	 while(index<maxn)
	 {
		 flag = true;
		 temp = Math.floor(Math.random() * maxn);
		 for(i=0;i<array.length;i++)
		 {
			 if(temp==array[i])
			 {
				flag=false;
				break;
			 }
		 }
		 
		 if(flag==true)
		 array[index++] = temp;
	 }
	 
	 return array;
 };
 
});

jQuery.easing['jswing'] = jQuery.easing['swing'];

jQuery.extend( jQuery.easing,
{
	def: 'easeOutQuad',
	swing: function (x, t, b, c, d) {
		//alert(jQuery.easing.default);
		return jQuery.easing[jQuery.easing.def](x, t, b, c, d);
	},
	easeInQuad: function (x, t, b, c, d) {
		return c*(t/=d)*t + b;
	},
	easeOutQuad: function (x, t, b, c, d) {
		return -c *(t/=d)*(t-2) + b;
	},
	easeInOutQuad: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t + b;
		return -c/2 * ((--t)*(t-2) - 1) + b;
	},
	easeInCubic: function (x, t, b, c, d) {
		return c*(t/=d)*t*t + b;
	},
	easeOutCubic: function (x, t, b, c, d) {
		return c*((t=t/d-1)*t*t + 1) + b;
	},
	easeInOutCubic: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t + b;
		return c/2*((t-=2)*t*t + 2) + b;
	},
	easeInQuart: function (x, t, b, c, d) {
		return c*(t/=d)*t*t*t + b;
	},
	easeOutQuart: function (x, t, b, c, d) {
		return -c * ((t=t/d-1)*t*t*t - 1) + b;
	},
	easeInOutQuart: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t*t + b;
		return -c/2 * ((t-=2)*t*t*t - 2) + b;
	},
	easeInQuint: function (x, t, b, c, d) {
		return c*(t/=d)*t*t*t*t + b;
	},
	easeOutQuint: function (x, t, b, c, d) {
		return c*((t=t/d-1)*t*t*t*t + 1) + b;
	},
	easeInOutQuint: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t*t*t + b;
		return c/2*((t-=2)*t*t*t*t + 2) + b;
	},
	easeInSine: function (x, t, b, c, d) {
		return -c * Math.cos(t/d * (Math.PI/2)) + c + b;
	},
	easeOutSine: function (x, t, b, c, d) {
		return c * Math.sin(t/d * (Math.PI/2)) + b;
	},
	easeInOutSine: function (x, t, b, c, d) {
		return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;
	},
	easeInExpo: function (x, t, b, c, d) {
		return (t==0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b;
	},
	easeOutExpo: function (x, t, b, c, d) {
		return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
	},
	easeInOutExpo: function (x, t, b, c, d) {
		if (t==0) return b;
		if (t==d) return b+c;
		if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b;
		return c/2 * (-Math.pow(2, -10 * --t) + 2) + b;
	},
	easeInCirc: function (x, t, b, c, d) {
		return -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b;
	},
	easeOutCirc: function (x, t, b, c, d) {
		return c * Math.sqrt(1 - (t=t/d-1)*t) + b;
	},
	easeInOutCirc: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return -c/2 * (Math.sqrt(1 - t*t) - 1) + b;
		return c/2 * (Math.sqrt(1 - (t-=2)*t) + 1) + b;
	},
	easeInElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
	},
	easeOutElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
	},
	easeInOutElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d/2)==2) return b+c;  if (!p) p=d*(.3*1.5);
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		if (t < 1) return -.5*(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
		return a*Math.pow(2,-10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )*.5 + c + b;
	},
	easeInBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158;
		return c*(t/=d)*t*((s+1)*t - s) + b;
	},
	easeOutBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158;
		return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
	},
	easeInOutBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158; 
		if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
		return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
	},
	easeInBounce: function (x, t, b, c, d) {
		return c - jQuery.easing.easeOutBounce (x, d-t, 0, c, d) + b;
	},
	easeOutBounce: function (x, t, b, c, d) {
		if ((t/=d) < (1/2.75)) {
			return c*(7.5625*t*t) + b;
		} else if (t < (2/2.75)) {
			return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
		} else if (t < (2.5/2.75)) {
			return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
		} else {
			return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
		}
	},
	easeInOutBounce: function (x, t, b, c, d) {
		if (t < d/2) return jQuery.easing.easeInBounce (x, t*2, 0, c, d) * .5 + b;
		return jQuery.easing.easeOutBounce (x, t*2-d, 0, c, d) * .5 + c*.5 + b;
	}
});

	function array2json(arr) 
	{
		var json_string																= "{";
		if(typeof(arr)=='object'&&(arr instanceof Array))
		{
			for(var myKey in arr)
			{
				if(myKey != 0)
				{
					json_string															+= ",";
				}
				var url 																	= arr[myKey]['url']; 
				var effect 																= arr[myKey]['effect']; 
				var delay																	= arr[myKey]['delay']; 
				var aHref																	= arr[myKey]['aHref'];
				var aTarget																= arr[myKey]['aTarget']; 
				var aTitle																= arr[myKey]['aTitle']; 
				json_string																+= '"'+myKey+'":{"url":"'+url+'","effect":"'+effect+'","delay":"'+delay+'","aHref":"'+aHref+'","aTarget":"'+aTarget+'","aTitle":"'+aTitle+'"';
				
				if(typeof(arr[myKey]['text'])=='object'&&(arr[myKey]['text'] instanceof Array) && arr[myKey]['text'].length > 0)
				{
					json_string														+= ',"text":[';
					for(var textKey in arr[myKey]['text'])
					{
						if(textKey != 0)
						{
							json_string															+= ",";
						}
						var x																	= arr[myKey]['text'][textKey]['x'];
						var y																	= arr[myKey]['text'][textKey]['y'];
						var width															= arr[myKey]['text'][textKey]['width'];
						var height														= arr[myKey]['text'][textKey]['height'];
						var direction													= arr[myKey]['text'][textKey]['direction'];
						var time															= arr[myKey]['text'][textKey]['time'] / 1000;
						var cdata															= addslashes(arr[myKey]['text'][textKey]['cdata']);
						cdata																	= cdata.replace("<a ", "TEXT_ATAG");
						json_string														+= '{"x":"'+x+'","y":"'+y+'","width":"'+width+'","height":"'+height+'","direction":"'+direction+'","time":"'+time+'","cdata":"'+cdata+'"}';
					}
					json_string														+= ']';
				}
				json_string															+= '}';
			}
			
			json_string																	+= "}";
		}
		else
		{
			return "{}"
		}
		return json_string;
	}

	function addslashes (str)
	{
		return (str + '').replace(/[\\"']/g, '\\$&').replace(/\u0000/g, '\\0');
	}

