//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Functions ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


//text Rotator
var headline_count,
	headline_interval,	
	old_headline = 0,
	current_headline = 0;

//text rotate function for ipad and IE
function headline_rotate_ipad() {
	current_headline = (old_headline + 1) % headline_count;
	jQuery("div.headline:eq(" + old_headline + ")").fadeOut(2000);
	jQuery("div.headline:eq(" + current_headline + ")").delay(1000).fadeIn(1000);
	//jQuery("div.headline:eq(" + old_headline + ")").hide("puff",{},1000);
	//jQuery("div.headline:eq(" + current_headline + ")").delay(2000).show("puff",{},1000);
	old_headline = current_headline;
}

//text rotate function for modern browsers
function headline_rotate_general() {
	current_headline = (old_headline + 1) % headline_count;
	//$("div.headline:eq(" + old_headline + ")").fadeOut(1700);
	//$("div.headline:eq(" + current_headline + ")").fadeIn(3000);
	jQuery("div.headline:eq(" + old_headline + ")").hide("puff",{},1000);
	jQuery("div.headline:eq(" + current_headline + ")").delay(2000).show("puff",{},1000);
	old_headline = current_headline;
}



//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Functions |!| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

jQuery(function($){
//========================================================================================================

//redirect on click
var contain = $('.container');
contain.click(function(){
   document.location.href='/reckson/about-us/';
}).css('cursor','pointer');






//--------------------------------------------------------------------------------------------------------





//tests for (iPad and IE) or (Modern Browsers) to execute proper image rotation and text cycle
if (navigator.userAgent.match(/Android|webOS|iPhone|iPod|iPad/i) || jQuery.browser.msie){
var headline = $('.headline');
	//text cycle for (iPad and IE)
	headline_count = headline.size();
	headline.addClass('no-script-hide');
	headline.hide();
	headline.eq(current_headline).show();
	headline_interval = setInterval(headline_rotate_ipad,10500);

	//image rotoator for (iPad and IE)
var strImgs = $('#strips-img');
strImgs.css('z-index',0);

	strImgs.cycle({
		fx: 'fade',
		speed: 1000,
		timeout: 10000
	});


}else{
	
	var headline = $('.headline');
		
		headline_count = headline.size();
		headline.addClass('no-script-hide');
		headline.hide();
		headline.eq(current_headline).show();

	headline_interval = setInterval(headline_rotate_ipad,16600);

	//complex image rotator for (Modern Browsers) 
	var	myCols = 24,
		fullIndexPool = [],
		indexPool = [],
		myRows = 1,
		col_x_rows = myCols * myRows,
		strImgs = $('#strips-img');

	for(i=0; i < col_x_rows; i++){
		fullIndexPool[i] = i;
	}
	
	//applied zindex, otherwise images block the headline text
	strImgs.css('z-index',0);
	strImgs.cycle({
		fx: 'tiles',
		speed: 5000,
		tiles:{cols: myCols,cssAfter:{left:0,top:0},cssBefore:{left:0,top:200},
			order:function(i){
				if(!indexPool.length){
					indexPool = fullIndexPool.slice(0);
				}

				var randomIndex = Math.floor(Math.random()*indexPool.length), returnIndex = indexPool[randomIndex];
					indexPool.splice(randomIndex,1);
					return returnIndex;
			},
			rows: myRows,
			//slows down 
			tileAnimationDelay: 100
		},
		timeout: 11600
	});
}

//--------------------------------------------------------------------------------------------------------
//removes headline bg-image  to deal with IE transparency issues
if (jQuery.browser.msie){
	jQuery('html').addClass('ie');
	//jQuery('#reckson-herospace .headline').css({'background-image':'none','background-color':'#000000','opacity':'.8','height':'104px'});
}else{
	return false;
}

//--------------------------------------------------------------------------------------------------------

//--------------------------------------------------------------------------------------------------------
//========================================================================================================
});//(document).ready |!|

