$(function() {

      $(".tweet").tweet({
          avatar_size: 32,
          count: 25,
          username: "MindWorld_NLD",
          loading_text: "searching twitter..."
      });

      //Feed the speech bubbles
      $.getJSON(  
         'http://search.twitter.com/search.json?callback=?&rpp=50&q=Heineken&lang=nl',  
         function(data) {  
 
              if(data.results != "undefined"){
                  for (i=0; i < data.results.length; i++)
                  {
                     contentArray[i] = data.results[i].text;
                  }
                }

             ActivateActionJackson();
         }  
      ); 
	
	       
      $('.speechBubbleRight').qtip({    
        content: '',
        show:    { 
                  ready: true,
                  effect: 'fade',
                  length: 430 
         
        },
        position: {
                  corner: {
                     tooltip: 'bottomLeft', // Use the corner...
                     target: 'topRight' // ...and opposite corner
                  }
        },
        style: { 
                name: 'light',
                padding: 7,
                fontSize: '11px',
                lineHeight: 1.1,
				backgroundColor: '#fff',
				backgroundImage: 'url(../media/template/textmask.png)',
				backgroundRepeat: 'no-repeat',
                tip: true, 
				width: { min: 47 },
				height: '12px',
                border: {
                    width: 2,
                    radius: 4,
                    color: '#f0b629'
                }
        }

    });
      
    $('.speechBubbleLeft').qtip({    
        content: '',
        show:    {  
                  ready: true,
                  effect: 'fade',
                  length: 430 
        },
        position: {
                  corner: {
                     tooltip: 'bottomLeft', // Use the corner...
                     target: 'topRight' // ...and opposite corner
                  }
        },
        style: { 
                name: 'light',
                padding: 7,
                fontSize: '11px',
                lineHeight: 1.1,
				backgroundColor: '#FFF',
				backgroundImage: 'url(../media/template/textmaskblue.png)',
				backgroundRepeat: 'no-repeat',
				width: { min: 47 }, 
                tip: true, 
				height: '12px',
                border: {
                    width: 2,
                    radius: 4,
                    color: '#408dba'
                }
        }
    });

		
	resizeFix(); 
	var self = this, resizeTimer = null;
	$(window).resize( function() {
		if (resizeTimer) clearTimeout(resizeTimer);
		resizeTimer = setTimeout(function() { resizeFix() }, 100);
	});


});

  resizeFix = function(){
	 	 if ($(window).height() <= 740){
			 $('.contentbags').hide();
		 }else{
			 $('.contentbags').show();
		 }
  }


  ActivateActionJackson = function(){
  
      var timer = 3000;   
      var timerIncrement = 4000;
      var timeoutArr  = [];
      var apiLeft = $('.speechBubbleLeft').qtip("api");
      var apiRight = $('.speechBubbleRight').qtip("api");
      var aTel = 0;
      var iTel=0

      for (iTel=0; iTel < contentArray.length ; iTel++)
      {
          if(iTel % 2 == 0)
         {
            timeoutArr[iTel] = setTimeout( function(){ 

                $('.speechBubbleLeft').qtip("hide");      
                $('.speechBubbleRight').qtip("show");
                //apiRight.updateContent(contentArray[aTel]);
                aTel++;

                if(aTel >= contentArray.length)
                   ActivateActionJackson()

            } ,timer);
         }
         else
         {
           timeoutArr[iTel] = setTimeout( function(){
              $('.speechBubbleRight').qtip("hide");           
              $('.speechBubbleLeft').qtip("show"); 
             // apiLeft.updateContent(contentArray[aTel]);            
              aTel++;

              if(aTel >= contentArray.length)
                   ActivateActionJackson()

           } ,timer);
         }
         timer = timer + timerIncrement;
      }  
   }