Cufon.replace('h1');
Cufon.replace('h2');
google.load('search', '1', {language : 'en'});
$(document).ready(function() {
	function megaHoverOver(){
		$(this).find(".sub").stop().fadeTo('fast', 0.95).show();
			
		//Calculate width of all ul's
		(function($) { 
			jQuery.fn.calcSubWidth = function() {
				rowWidth = 0;
				//Calculate row
				$(this).find("ul").each(function() {					
					rowWidth += $(this).width(); 
				});	
			};
		})(jQuery); 
		
		if ( $(this).find(".row").length > 0 ) { //If row exists...
			var biggestRow = 0;	
			//Calculate each row
			$(this).find(".row").each(function() {							   
				$(this).calcSubWidth();
				//Find biggest row
				if(rowWidth > biggestRow) {
					biggestRow = rowWidth;
				}
			});
			//Set width
			$(this).find(".sub").css({'width' :biggestRow});
			$(this).find(".row:last").css({'margin':'0'});
			
		} else { //If row does not exist...
			
			$(this).calcSubWidth();
			//Set Width
			$(this).find(".sub").css({'width' : rowWidth});
			
		}
	}
	
	function megaHoverOut(){ 
	  $(this).find(".sub").stop().fadeTo('fast', 0, function() {
		  $(this).hide(); 
	  });
	}
 
	var config = {    
		 sensitivity: 2, // number = sensitivity threshold (must be 1 or higher)    
		 interval: 0, // number = milliseconds for onMouseOver polling interval    
		 over: megaHoverOver, // function = onMouseOver callback (REQUIRED)    
		 timeout: 0, // number = milliseconds delay before onMouseOut    
		 out: megaHoverOut // function = onMouseOut callback (REQUIRED)    
	};
 
	$("ul#topnav li .sub").css({'opacity':'0'});
	$("ul#topnav li").hoverIntent(config);
 
	// This initialises carousels on the container elements specified, in this case, carousel1.
	$("#carousel1").CloudCarousel(		
		{			
			xPos: 490,
			yPos: 32,
			buttonLeft: $("#left-but"),
			buttonRight: $("#right-but"),
			xRadius: 400,
			yRadius: -20,
			reflHeight:100,
			reflGap:-77,
			reflOpacity:0.5,
			autoRotate:'right',
			autoRotateDelay:5000
			/*altBox: $("#alt-text"),
			titleBox: $("#title-text")*/
		}
	);
	
	// link highlight
				
	var path = window.location.toString().split("/");
	var topmenu = window.location.toString().split("?");
	path = path[path.length - 1];
	topmenu = topmenu[topmenu.length -1];
	topmenu = topmenu.split("=");
	topmenu = topmenu[topmenu.length - 1];
	if (path) {
	$('ul#topnav li > a').each(function() {
			var $category = $(this).attr('id');
			if (path.indexOf($category) >= -1) {
				$("#"+topmenu).addClass("selected");
				$("ul#topnav a[href=\""+path+"\"]").addClass("selected");
				$(".verticalmenu a[href=\""+path+"\"]").addClass("subselected");
			}
		});              
	}
	// end
	
	
	// perform JavaScript after the document is scriptable.
	$(function() {
		// setup ul.tabs to work as tabs for each div directly under div.panes
		$("ul.tabs").tabs("div.panes > div");
	});
	
	// pagination - national events
	var pagination_options = {
      num_edge_entries: 1,
      num_display_entries: 2,
      callback: pageselectCallback,
      items_per_page:2
    }
    function pageselectCallback(page_index, jq){
      var items_per_page = pagination_options.items_per_page;
      var offset = page_index * items_per_page;
      var new_content = $('#hiddenresult span.result').slice(offset, offset + items_per_page).clone();
      $('#Searchresult').empty().append(new_content);
      return false;
    }
    function initPagination() {
      var num_entries = $('#hiddenresult span.result').length;
      // Create pagination element
      $("#Pagination").pagination(num_entries, pagination_options);
    }
    initPagination();
	
	
	// pagination 2 - international events
	var pagination_options = {
      num_edge_entries: 1,
      num_display_entries: 2,
      callback: pageselectCallback1,
      items_per_page:2
    }
    function pageselectCallback1(page_index, jq){
      var items_per_page = pagination_options.items_per_page;
      var offset = page_index * items_per_page;
      var new_content = $('#hiddenresult2 span.result1').slice(offset, offset + items_per_page).clone();
      $('#Searchresult2').empty().append(new_content);
      return false;
    }
    function initPagination1() {
      var num_entries = $('#hiddenresult2 span.result1').length;
      // Create pagination element
      $("#Pagination2").pagination(num_entries, pagination_options);
    }
    initPagination1();
	
	
	
	// pagination 3 - international events
	var pagination_options = {
      num_edge_entries: 1,
      num_display_entries: 2,
      callback: pageselectCallback3,
      items_per_page:2
    }
    function pageselectCallback3(page_index, jq){
      var items_per_page = pagination_options.items_per_page;
      var offset = page_index * items_per_page;
      var new_content = $('#hiddenresult3 span.result3').slice(offset, offset + items_per_page).clone();
      $('#Searchresult3').empty().append(new_content);
      return false;
    }
    function initPagination3() {
      var num_entries = $('#hiddenresult3 span.result3').length;
      // Create pagination element
      $("#Pagination3").pagination(num_entries, pagination_options);
    }
    initPagination3();
	
	// end
	
	// pagination 4 - international events
	var pagination_options = {
      num_edge_entries: 1,
      num_display_entries: 2,
      callback: pageselectCallback4,
      items_per_page:2
    }
    function pageselectCallback4(page_index, jq){
      var items_per_page = pagination_options.items_per_page;
      var offset = page_index * items_per_page;
      var new_content = $('#hiddenresult4 span.result4').slice(offset, offset + items_per_page).clone();
      $('#Searchresult4').empty().append(new_content);
      return false;
    }
    function initPagination4() {
      var num_entries = $('#hiddenresult4 span.result4').length;
      // Create pagination element
      $("#Pagination4").pagination(num_entries, pagination_options);
    }
    initPagination4();
	
	// end
	
	
	// pagination 5 - international events
	var pagination_options = {
      num_edge_entries: 1,
      num_display_entries: 2,
      callback: pageselectCallback5,
      items_per_page:2
    }
    function pageselectCallback5(page_index, jq){
      var items_per_page = pagination_options.items_per_page;
      var offset = page_index * items_per_page;
      var new_content = $('#hiddenresult5 span.result5').slice(offset, offset + items_per_page).clone();
      $('#Searchresult5').empty().append(new_content);
      return false;
    }
    function initPagination5() {
      var num_entries = $('#hiddenresult5 span.result5').length;
      // Create pagination element
      $("#Pagination5").pagination(num_entries, pagination_options);
    }
    initPagination5();
	
	// end
	
	
	// pagination 6 - CIPL, CAT, DCVG &amp; Pearson Survey
	var pagination_options = {
      num_edge_entries: 1,
      num_display_entries: 2,
      callback: pageselectCallback6,
      items_per_page:2
    }
    function pageselectCallback6(page_index, jq){
      var items_per_page = pagination_options.items_per_page;
      var offset = page_index * items_per_page;
      var new_content = $('#hiddenresult6 span.result6').slice(offset, offset + items_per_page).clone();
      $('#Searchresult6').empty().append(new_content);
      return false;
    }
    function initPagination6() {
      var num_entries = $('#hiddenresult6 span.result6').length;
      // Create pagination element
      $("#Pagination6").pagination(num_entries, pagination_options);
    }
    initPagination6();
	
	// end
	
	
	
	$(".slidingDiv").hide();
	$(".show_hide").show("slow");
	
	$('.show_hide').click(function(){
		$(".slidingDiv").slideToggle();
	});
	$(".show_hide").toggle(function() {
		$(this).html('&laquo; Close');
		}, function() {
		$(this).html('&raquo; Expand');
		});
		
		

		
	$("#searchbtn").click(function () {
		var customSearchControl = new google.search.CustomSearchControl('006727043802769870575:mvzuqlfxnsg');
		customSearchControl.setLinkTarget(google.search.Search.LINK_TARGET_PARENT);
		customSearchControl.setResultSetSize(google.search.Search.FILTERED_CSE_RESULTSET);

		$("#searchbtn").colorbox({width:"800px", height: "600px", inline:true, href:"#results1"});

		customSearchControl.draw(document.getElementById("results1"));
		customSearchControl.execute(document.getElementById("query_input").value);
	});
	
		
});

      


