$(document).ready(function(){
	
	// General
	$('.revealer_red div').hide();
	
	$('.revealer_red h2').click(function() {
		$(this).next('div').toggle();
		
		if ( $(this).next('div').is(':visible')){
			$(this).removeClass('revealer_red_right_arrow');
			$(this).addClass('revealer_red_down_arrow');
		} else {
			$(this).addClass('revealer_red_right_arrow');
			$(this).removeClass('revealer_red_down_arrow');
		}  
	});
	
	$('.revealer_red h2').hover(
		function() {
			$(this).stop().addClass('revealer_red_hover');
		},
		function() {
			$(this).stop().removeClass('revealer_red_hover');
		}
	);
		
	$('.fade_img').hover(
		function() {
			$(this).animate({	opacity: 0.4}, 250);
		},
		function() {
			$(this).animate({	opacity : 1.0 }, 750);
		}
	);
	
	// Program
	$('.program_table tbody tr:even').addClass('program_table_shade_even');
	
	$('.program_table tbody tr').hover(function(){
		$(this).addClass('program_table_hover');
	}, function(){
		$(this).removeClass('program_table_hover');
	});
	
	$('.program_table tbody tr').click(function() {
		//$target = $('.program_table tbody tr a').attr('href');
		//alert( $target );
		window.location=$(this).find("a").attr("href"); 
		return false;
	});
	
	// no link table
	$('.no_link_table tbody tr:even').addClass('no_link_table_shade_even');
	
	// Oor die Maatskappy
	//$('#oor_barousel').barousel();
	$('#oor_barousel').barousel({
  	navType: 2,
		manualCarousel: 0
	});
	
	// Home slideshow
	slideShow();
	/*
	$('#home_slideshow').crossSlide({
		speed: 30,
		fade: 2
	}, [
		{ src: 'images/slides/kunste_kom_bymekaar_1.jpg', dir: 'down' },
		{ src: 'images/slides/kunste_kom_bymekaar_2.jpg', dir: 'up' },
		{ src: 'images/slides/kunste_kom_bymekaar_3.jpg', dir: 'up' },
		{ src: 'images/slides/kunste_kom_bymekaar_4.jpg', dir: 'down' },
		{ src: 'images/slides/kunste_kom_bymekaar_5.jpg', dir: 'up' }
	]);
	*/
	
	// call non-jQuery functions
	topnav_menu();					// navigation
	ek_wil();								// 'Ek wil / I want to' drop-down
	//g_maps_initialize();		// Google Maps *********************************** This clashes with CrossSlide
	
});

function g_maps_initialize() {
	var latlng = new google.maps.LatLng(-33.592, 22.200);																	// center of map
	var myOptions = {
		zoom: 15,
		center: latlng,
		mapTypeId: google.maps.MapTypeId.ROADMAP
	};
	var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);			// create map
	
	var imageKKNK = 'images/kontak/KKNK_location.png';																				// KKNK marker icon
	var latlngKKNK = new google.maps.LatLng(-33.59270, 22.20480);													// marker location
	var kknkMarkerOptions = {																															// marker options
		map: map,																																						// map to use for marker
		title: "Absa KKNK - Seppie Greeff Gebou, Voortrekker Straat",										// marker title (tooltip)
		visible: true,
		icon: imageKKNK,
		position: latlngKKNK
	};
	var kknkMarker = new google.maps.Marker( kknkMarkerOptions );													// create kknk marker
}

/* 
  ------------------------------------
  PVII Menu CSS Express Drop-Down Menu
  by Project Seven Development
  www.projectseven.com
  ------------------------------------
*/
function topnav_menu(){ //v1.1.0.2 by PVII-www.projectseven.com
 if(navigator.appVersion.indexOf("MSIE")==-1){return;}
 var i,k,g,lg,r=/\s*top_nav_hvr/,nn='',c,cs='top_nav_hvr',bv='top_nav';
 for(i=0;i<10;i++){g=document.getElementById(bv+nn);if(g){
 lg=g.getElementsByTagName("LI");if(lg){for(k=0;k<lg.length;k++){
 lg[k].onmouseover=function(){c=this.className;cl=(c)?c+' '+cs:cs;
 this.className=cl;};lg[k].onmouseout=function(){c=this.className;
 this.className=(c)?c.replace(r,''):'';};}}}nn=i+1;}
}

function ek_wil(){ //v1.1.0.2 by PVII-www.projectseven.com
 if(navigator.appVersion.indexOf("MSIE")==-1){return;}
 var i,k,g,lg,r=/\s*ek_wil_hvr/,nn='',c,cs='ek_wil_hvr',bv='ek_wil';
 for(i=0;i<10;i++){g=document.getElementById(bv+nn);if(g){
 lg=g.getElementsByTagName("LI");if(lg){for(k=0;k<lg.length;k++){
 lg[k].onmouseover=function(){c=this.className;cl=(c)?c+' '+cs:cs;
 this.className=cl;};lg[k].onmouseout=function(){c=this.className;
 this.className=(c)?c.replace(r,''):'';};}}}nn=i+1;}
}

function slideShow() {

	//Set the opacity of all images to 0
	$('#home_slideshow a').css({opacity: 0.0});
	
	//Get the first image and display it (set it to full opacity)
	$('#home_slideshow a:first').css({opacity: 1.0});
	
	//Set the caption background to semi-transparent
	$('#home_slideshow .caption').css({opacity: 0.6});

	//Resize the width of the caption according to the image width
	$('#home_slideshow .caption').css({width: $('#home_slideshow a').find('img').css('width')});
	
	//Get the caption of the first image from REL attribute and display it
	$('#home_slideshow .content').html($('#home_slideshow a:first').find('img').attr('rel'))
	.animate({opacity: 0.9}, 300);
	
	//Call the gallery function to run the slideshow, 6000 = change to next image after 6 seconds
	setInterval('gallery()',4500);
	
}

function gallery() {
	
	//if no IMGs have the show class, grab the first image
	var current = ($('#home_slideshow a.show')?  $('#home_slideshow a.show') : $('#home_slideshow a:first'));

	//Get next image, if it reached the end of the slideshow, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('caption'))? $('#home_slideshow a:first') :current.next()) : $('#home_slideshow a:first'));	
	
	//Get next image caption
	var caption = next.find('img').attr('rel');	
	
	//Set the fade in effect for the next image, show class has higher z-index
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1000);

	//Hide the current image
	current.animate({opacity: 0.0}, 1000)
	.removeClass('show');
	
	//Set the opacity to 0 and height to 1px
	$('#home_slideshow .caption').animate({opacity: 0.0}, { queue:false, duration:0 }).animate({height: '250px'}, { queue:true, duration:0 });	
	
	//Animate the caption, opacity to 0.7 and heigth to 100px, a slide up effect
	$('#home_slideshow .caption').animate({opacity: 0.9},200 ).animate({height: '25px'},650 );
	
	//Display the content
	$('#home_slideshow .content').html(caption);	
	
}
