$(document).ready(function(){

	/* blockUI global overrides */
	$.blockUI.defaults.css.padding			= '5px';
	$.blockUI.defaults.css.color			= '#29261b';
	$.blockUI.defaults.css.border			= '2px solid #2e2c23';
	$.blockUI.defaults.css.backgroundColor	= '#f0f0f0';
	$.blockUI.defaults.css.cursor			= 'default';
	$.blockUI.defaults.overlayCSS.cursor	= 'default';
	$.blockUI.message						= '<h1>Please wait...</h1>';

	/* Observe Confirmations */
	observe_confirm = function() {
		var link = this.href;
				
		$.ajax({
			url: link, 
			cache: false,
			complete: function(html) { 
				$.blockUI({ message: '<p>'+html.responseText+'</p>'}); 
			}
		});

		$('#confirm_cancel').click(function() {
			$.unblockUI();
			return false;
		});
		
		return false;
	}
	
	
	// Add confirmations to delete links
	$('.confirm').click(observe_confirm);
		
		
		
		
		
		
	/* search box */
		//textReplacement($('#search'));
		$('#search').css('border', '1px #ffffff');
		
		/* preloading images */
		$('img.mainnavigate').preload({
			find: '_inactive.png', replace: '_active.png'
		});
		
		/* main navigation */
		$("img.mainnavigate, .navigation").hover(function(){ 
							$(this).attr('src', $(this).attr('src').replace(/_inactive/g,'_active')); }
				,function(){ 
						$(this).attr('src', $(this).attr('src').replace(/_active/g,'_inactive')); 

						var className = this.className;
						
						className = className.split(' ');
						
						if (className[1] == 'main_navigate_activate')							
							$(this).attr('src', $(this).attr('src').replace(/_inactive/g,'_active')); 
						
						}
		
				);
		

	
	
		/* whitepapers - frontpage */
		/* correction must be made 
		
			the number of active whitepapers for front page must be properly selected
			if < 6 then must be equal to the numbers
			else 
				MUST be = 6
		*/
		
		if (NO_FRONT_WHITEPAPERS <= 6){
			NO_FRONT_WHITEPAPERS = NO_FRONT_WHITEPAPERS - 1;
		}else {
			NO_FRONT_WHITEPAPERS = 6;
		}
		
		
		$("#whitepage_thumbs").jCarouselLite({
					speed: 60,
					btnNext: ".jcl_next",
					btnPrev: ".jcl_prev",
					visible: NO_FRONT_WHITEPAPERS					
				});
				
		$("#rotate_community").jCarouselLite({
		    auto: 800,
		    speed: 3000,
		    visible: 1.0005,
					btnNext: ".next",
					btnPrev: ".prev",
					btnPause: ".pause"
		});

		
		var orig = null;
		$('li.hovera div').hover(function(){
					//remove all the class within the ul
					orig = $('#white_papers').children('.hovera');
					ictr = 0; 
					for (ictr=0; ictr < orig.length; ictr++){
						$(orig[ictr]).find('div').removeClass();
					}
					
					//make the present selected white paper active
					$(this).addClass('whitepage_thumbnail');
				},function(){
					//maintain the white border and not remove it
					//$(this).removeClass('whitepage_thumbnail');
				});
				
				
		$('li.hovera').hover(
		
					function(){
			
						//alert($(this).find('> a > div > label').html());
			
						/* $.getJSON(BASE_URL + "ajax_controller/get_whitepage_info/"+$(this).find('> a > div > label').html(), function(retval){
	
						      if (retval.length > 0){
						      	$('#whitepage_head').html(retval[0].title);
								$('#whitepage_body').html(retval[0].description);
						      }
						      
	
					    })*/
					  
					    if ($(this).find('> div > a > label').html()){
						      	$('#whitepage_head').html(rawurldecode(arr[$(this).find('> div > a > label').html()][0]));
								$('#whitepage_body').html(rawurldecode(arr[$(this).find('> div > a > label').html()][1]));
					    }
					    
					    
					    
					
					}, 
					function(){}
		);
		
		
		$('.hoverit, .hoverit p, .hoverit span').hover(function(){
					$(this).addClass('underline');
					$(this).children().addClass('underline');
				},function(){
					$(this).removeClass('underline');
					$(this).children().removeClass('underline');
				});
		
		
		/* whitepapers - our insights */
		$('.out_whitepaper').hover(function(){
				$(this).css('cursor', 'pointer');
				$(this).css('background', '#004c82');
				$(this).find('img.arrow').css('display','block');

		}, function(){
				$(this).css('cursor', 'none');
				$(this).css('background', 'none');
				$(this).find('img.arrow').css('display','none');
		});

		/* whitepapers - our insights */
		$('.thumb_arrow').hover(function(){
				$(this).css('cursor', 'pointer');
				$(this).find('img.arrow').css('display','block');

		}, function(){
				$(this).css('cursor', 'none');
				$(this).css('background', 'none');
				$(this).find('img.arrow').css('display','none');
		});
		

		/* whitepapers dropdown */
		$('#date_dropdown').change(function(){
			window.location = $(this).val();
		});
		
		/* whitepapers - popup */
		$("img[src*='_t.']").thumbPopup({
				popupCSS: {'border': '0', 'width': '275px', 'height': '464px', 'background': '#807f84'},
				imgSmallFlag: "_t",
				imgLargeFlag: "_l",
				additionalContentIDorClass: '.out_whitepaper_content'
		}); // provide the id of the additional content element
	    
		/* email encoding - from php to javascript encoding */
		$('a[href^=mailto:]').each(

			function(i){
				
				var strTemp = $(this).html();
				
				strTemp = strTemp.replace(/\[dot\]/g,'.');
				strTemp = strTemp.replace(/\[at\]/g,'@')				
				

				$(this).html(strTemp);
			}

		);


		/*****************************************************************************************/
		/*****************************************************************************************/
		/* this area handles the resizing of the left and right boxes 							 */
		/*****************************************************************************************/
		/*****************************************************************************************/
		
		function doSomething(){

			//content is lesser than min-template height		
				$('.tdLeft').height($('.tdContent').height());
				$('.tdRight').height($('.tdContent').height());
				
				$('.cleft').css('height', $('.tdLeft').height() - 15);			
				$('.cright').css('height', $('.tdRight').height() - 15);
				
				$('.cleft_kid').css('height', $('.cleft').height() - 55);
				$('.cright_kid').css('height', $('.cright').height() - 55);
			
		}
			
		 var resizeTimer = null;
		$(window).bind('resize', function() {
				    if (resizeTimer) clearTimeout(resizeTimer);
				    resizeTimer = setTimeout(doSomething, 100);
		});
		
		doSomething();
		
		
		// text replacement function
		function textReplacement(input){
		 var originalvalue = input.val();
		 input.focus( function(){
		  if( $.trim(input.val()) == originalvalue ){ input.val(''); }
		 });
		 input.blur( function(){
		  if( $.trim(input.val()) == '' ){ input.val(originalvalue); }
		 });
		}
	 
				
});
