var delay = 600;
var intervalID;
var path;
$(document).ready(function(){
		if($(".blink").length>0){			
			SetInterval();	
			$(".blink.toggle").mouseover(function(){
							$(this).stop(true,true);
							if(!$(this).attr('src'))return;
							if($(this).attr('src').toString().indexOf(".jpg")!=-1){
								//console.log('this is the promis image');
								path = $(this).attr('src').toString().replace('.','1.'); 
							}
							else{
								//console.log('this is the  image');	
								path = $(this).attr('src').toString()+"&red=true"; 
							}
							$(this).attr('src',path);
							clearInterval(intervalID);							
						})
			           .mouseout(function(){
							if(!$(this).attr('src'))return;			  	
							if($(this).attr('src').toString().indexOf(".jpg")!=-1){
								//console.log('this is the promis image');
								path = $(this).attr('src').toString().replace('1.','.'); 
							}
							else{
								path = $(this).attr('src').toString().split('&')[0];			  
							}
							$(this).attr('src',path);	
							SetInterval();							
						})
		}
});

function SetInterval(){
	MakeBlink();
	intervalID = setInterval(MakeBlink,(delay*2)+100);
}

function MakeBlink(){		
	var elements = $(".blink");
	if(elements.length>0){				
		elements.each(function(){
				/*$(this).fadeTo('normal',0.33,function(){
							$(this).fadeTo('normal',1);						
						});*/
				$(this).animate({opacity:0.43},delay,function(){
						$(this).animate({opacity:1.0},delay);									 
				});								
		});
	}	
}
