﻿// document ready
$(function() {
	$(".labeler").labeler();
	$(".afalc").afalc();
	$("#content").moveClass("body");
	$("#content input").typeClass("input_type");
	$(".odd").oddEven();
	$(".tablestripe").oddEven({target:"tbody tr"});
	//$(".level1 ul li a").tooltiper({position:"left bottom tl", hideDelay:40, showDelay:200});
	initDatePicker();
	createTabs();
	videoPagination();
	
	$(".setNumberOfColumns3").columnise(".sublead", {numberOfColumns:3});
	$(".setNumberOfColumns2").columnise(".sublead", {numberOfColumns:2});
	$(".row").columns(".column");
	

    $(".template_114 div.subleadRHScontainer, .template_115 div.subleadRHScontainer, .template_116 div.sublead_bottom").randomize("div.subleadRHS");


	
	
});

// document load 
$(window).load(function() {
	startLeadelement();
});




 


(function($) {

$.fn.randomize = function(childElem) {
  return this.each(function() {
      var $this = $(this);
      var elems = $this.children(childElem);

      elems.sort(function() { return (Math.round(Math.random())-0.5); });  

      $this.remove(childElem);  

      for(var i=0; i < elems.length; i++)
        $this.append(elems[i]);    //set to i for same number, limiting to 6     

      });    
	  
	  
	  
	  
}
})(jQuery);




function initDatePicker() {
	// Datepickers for date input fields
	$('input.date').datepicker({ dateFormat: 'dd/mm/yy' });
}
 
// Open an AJAX dialog
function openDialog(url,title,width,height) {
	// Width and height
	var w = 500;
	var h= 300;
	if(width) {
		w = width;	 
	}
	if(height) {
		h = height;	 
	}
	 // Reset the dialog
    $("#dialog").html('').dialog('destroy'); 
    // Set up dialog
    $("#dialog").dialog({
		width: w,
		height: h,
		modal: true,
		title: title,
		cache: false
    }); 
    // Fetch content
    $.ajax({
		type: "GET",
		url: url,
		data: "ajax=1",
		success: function(data){
			$("#dialog").html(data);
		}
    });
}

// Replace alrt boxes with a much nicer alternative
function ajaxAlert(msg) {
	if($('#alert').length == 0) {
		$("body").append('<div id="alert"></div>');	
	}
    $('#alert').dialog('destroy').html(msg).dialog({
		dialogClass: 'alert',
		width: 200,
		minHeight: 80,
		modal: true,
		cache: false,
		buttons: { "Ok": function() { $(this).dialog("close"); } }
    }); 
}

/* create tabs function - to allow for tabs to be called by other means */
function createTabs(){
	$(".tabs").tabber();
}

function printPage() {
    window.print();
}

function startLeadelement() {	
   $('.cycle_slideshow').cycle({
        fx:      'fade',
        timeout:  0,
        prev:    '#prev',
        next:    '#next',
        pager:   '.pager',
		timeout: 6000, 
        pagerAnchorBuilder: pagerFactory
    });

    function pagerFactory(idx, slide) {
        var s = idx > 10 ? ' style="display:none"' : '';
        return '<li'+s+'><a href="#">'+(idx+1)+'</a></li>';
    };
}

function videoPagination() {	
   $('.video_list').cycle({
        fx:      'fade',
        timeout:  0,
        prev:    '#prev',
        next:    '#next',
        pager:   '.pager',
		timeout: 0, 
        pagerAnchorBuilder: pagerFactory
    });

    function pagerFactory(idx, slide) {
        var s = idx > 10 ? ' style="display:none"' : '';
        return '<li'+s+'><a href="#">'+(idx+1)+'</a></li>';
    };
}




