// <![CDATA[
/******************************************************************************************
* Module: siworks.extention.js
* Version: 2.1.2
* Created: 20090918
* Description: We are now going to further extend the DOM via prototype.js much
* more effective way of doing things, we bind everything together this way
* @copyright		2009 SI-Works, All rights reserved
* @author			$Author: kgotso $
* @email			<support@siworks.co.za>
* @link				http://www.siworks.co.za
* @version			$Revision: 88 $
* $Id: siworks.extention.js 88 2011-03-10 10:39:03Z kgotso $
* 
* Copyright:  SI Works internet var year = new Date(); year.getFullYear();
* 
* Email:  support@siworks.co.za
* Author: Greg Shiers, Jarratt Ingram
******************************************************************************************/
navigateTourism = function () {
 	if ($('#select_type_tourism').selectedIndex == 0) {
		return false;
	}
	else {
		location.href = '/index.php?menu=tourism&submenu=section&option='+$('#select_type_tourism').val();
	}
}
navigateTourismSubmenus = function () {
 	if ($('#select_type_tourism').selectedIndex == 0) {
		return false;
	}
	else {
		location.href = '/index.php?menu=tourism&submenu=cat&option='+$('#select_type_tourism').val();
	}
}
preSelectTourismSelectBox = function () {
	 if( $('#select_type_tourism').length > 0) {
	 	var values = location.href.split('option=')[1];
		$('#select_type_tourism').val(values); 
	 }
}
function showhide (element) {
 	if ($("#"+element).css('display') == 'none') {
		$("#"+element).slideDown(300);
	}
	else {
		$("#"+element).slideUp(300);
	} 
}
Array.prototype.inArray = function (value) {
	var i;
	for (i=0; i < this.length; i++) {
		if (this[i] === value) {
			return true;
		}
	}
	return false;
};
/** load global href array **/
var page = location.href;
var activePage = page.split('menu=')[1];

var profileArray 			= ['About_us', 'Contractual_Framework', 'Funding', 'Operations_and_Maintenance', 'The_Project'];
var csiArray 				= ['2010_C_S_I','2011_C_S_I', 'Charity_Golf_Day', '2011_Bapong_Workshop', 'Bapong_Workshop_Road_Safety', '2011_Cycle_4_Life', 'The_Cycle_for_Life_competition', '2011_World_Cancer_Day', 'World_Cancer_Day','CSI_Application_forms','Policy_Statement','Social_investment'];
var etagArray 				= ['etag', 'e_tag_Administration_FAQ_s', 'e_tag_Payment_FAQ_s', 'Obtaining_an_e_tag_FAQ_s', '', ''];
var environmentArray 		= ['Environmental_Initiatives', 'Environmental_Policy_statement'];
var overloadArray 			= ['Legal_load_limits_explained', 'Mantsole_Traffic_Control_Centre', 'Overload_and_Trucking_overview'];
var roadSafetyArray 		= ['Awareness_and_education', 'How_to_read_the_blue_boards'];
var routemapArray 			= ['N1_Tshwane_to_Bela_Bela', 'N4_Rustenburg_to_Botswana', 'N4_Tshwane_to_Rustenburg'];
var tourismArray 			= ['tourism&submenu=section&option=1', 'tourism&submenu=section&option=3', 'tourism&submenu=section&option=2'];
var trafficControlArray 	= ['Bapong_Traffic_Control_Centre_BTTC_', 'Beitbridge_Traffic_Control_Centre_BBTCC_', 'Mantsole_Traffic_Control_Centre_MTCC_'];


loadMenuActiveClass = function () {
	
	if ( profileArray.inArray(activePage) ) {
		$("#list-42").parent().find('a:first').addClass('active');
		$("#list-42").show();
	}
	if ( csiArray.inArray(activePage) ) {
		$("#list-43").parent().find('a:first').addClass('active');
		$("#list-43").show();
	}
	if ( etagArray.inArray(activePage) ) {
		$("#list-27").parent().find('a:first').addClass('active');
		$("#list-27").show();
	}
	if ( environmentArray.inArray(activePage) ) {
		$("#list-136").parent().find('a:first').addClass('active');
		$("#list-136").show();
	}
	if ( overloadArray.inArray(activePage) ) {
		$("#list-26").parent().find('a:first').addClass('active');
		$("#list-26").show();
	}
	if ( roadSafetyArray.inArray(activePage) ) {
		$("#list-24").parent().find('a:first').addClass('active');
		$("#list-24").show();
	}
	if ( routemapArray.inArray(activePage) ) {
		$("#list-41").parent().find('a:first').addClass('active');
		$("#list-41").show();
	}
	if ( tourismArray.inArray(activePage) ) {
		$("#list-148").parent().find('a:first').addClass('active');
		$("#list-148").show();
	}
	if ( trafficControlArray.inArray(activePage) ) {
		$("#list-154").parent().find('a:first').addClass('active');
		$("#list-154").show();
	}
}


loadSubMenuActiveClass = function () {
	$('#home-leftbar ul ul li a').each(function( index, element){
//		var activeHref =  $(element).attr('href').split('menu=')[1];
//		if ( activePage == activeHref ) {
//			$(element).addClass('active');
//		}
	})
}

$(document).ready(function(){
	/* Load fancy box onto the gallery images **/
	loadMenuActiveClass();
	loadSubMenuActiveClass();
	preSelectTourismSelectBox();
	
	$('#coda-slider-1').codaSlider({
		autoSlide: true, // automatic rotation between the banners		
        firstPanelToLoad: 5,
		// autoSlideInterval: 5000, // how long in miliseconds till next rotation
		//delayAutoSlide: 5000, // how long to pause on each banner
		//slideEaseDuration: 1000,
	});
	
	
	
	$('.top').bind('click', function( event ) {
		$('.top').removeClass('active');
		if ($(this).parent().find('ul').css('display') == 'none' ) {
			event.preventDefault();
			$(this).addClass('active');
			$("#home-leftbar ul ul").slideUp(200);
			$(this).parent().find('ul').slideDown(200);
		}
		else {
			if ( $(this).parent().find('ul').length > 0 ) {
				event.preventDefault();
				$(this).parent().find('ul').slideUp(200);
			}
			
		}
		//alert($(this).parent().html());
	});
	
	/* trigger the flyout to be closed, which ever it is */
	$(".close-button").bind("click", function() {
		$(this).parent().parent().parent().parent().slideUp(100);
	});
	
	/* Trigger the Stay informed flyout */
	$("#stay-informed-link a").bind('click', function( event ) {
		event.preventDefault();
		$(".topmenu-flyout-holder").slideUp(100);
		if ( $("#stay-informed").css('display') == 'none' ) {
			$("#stay-informed").slideDown(100);
		}
		else {
			$("#stay-informed").slideUp(100);
		}
	});
	/* Trigger the GPS Coordinades flyout */
	$("#gps-link a").bind('click', function( event ) {
		event.preventDefault();
		$(".topmenu-flyout-holder").slideUp(100);
		if ( $("#gps-coords").css('display') == 'none' ) {
			$("#gps-coords").slideDown(100);
		}
		else {
			$("#gps-coords").slideUp(100);
		}
	});
	
	
	/* View images using lightbox */	
	$('.csi-gallery a').fancybox({'titleShow' : false});
	
	$('.gallery_picture a').fancybox({'titleShow' : false});
	
	$("#routemap-block").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	350, 
		'speedOut'		:	200, 
		'overlayShow'	:	true,
		'type'			: 'iframe',
		'href'			: '/roadmap.php',
		'width'			: 900,
		'height'		: 650
	});
	
	$(".bosveld-myl .panel-wrapper a").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	350, 
		'speedOut'		:	200, 
		'overlayShow'	:	true,
		'type'			: 'iframe',
		'href'			: '/images/marico-myl-large.jpg',
		'width'			: 500,
		'height'		: 704
	});
	
	$(".lightview").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'titleShow'		: 	false,
		'speedIn'		:	350, 
		'speedOut'		:	200, 
		'overlayShow'	:	true,
		'type'			: 'iframe',
		'href'			: $(this).attr('href'),
		'width'			: 900,
		'height'		: 680
	});
	
	 
})			
// ]]>


