// -----------------------------------------------------------------------------------
// GLOBAL VARIABLES
// -----------------------------------------------------------------------------------

var jCC_Input_Search = 'Zoekterm';


// -----------------------------------------------------------------------------------
// UNIVERSAL CHECK IF OBJECT EXISTS
// -----------------------------------------------------------------------------------
function checkObject(jID) { 
	try { var o = document.getElementById(jID); if (o) { return true } else { return false }
	} catch (excp) { return false }
}


// Hides the search form
function cc_hide_search() {
	$('.cc_search').removeClass('cc_invert_hover');
	$('#menu_intro').html('').show(0);
	$('#menu_search').hide(0);
}


// -----------------------------------------------------------------------------------
// JQUERY INITS
// -----------------------------------------------------------------------------------
 $(document).ready(function(){ 

	// CONTENT add [+] to textlinks
	$('#content_cnt A').each(function(){ 

		if (checkObject("content_left_text") || checkObject("content_right_text") || checkObject("content_full_text")) { // for content pages only 
				// add title attribute & invert
				$(this).attr('title', 'url: ' + $(this).attr('href')).addClass("cc_invert");
		} else { // for overview pages only

			if ($(this).parents('H2').length==0) {	// do not execute for H2 tags
					if (($(this).text()=='[+]') || ($(this).parents('UL#search_footer').length!=0)) { $(this).addClass('cc_read_more');
					} else { $(this).append('&nbsp;<span class="cc_read_more">[+]</span>');	}
			}
		}
	});


	// HOME CONTENT FULL HOVER
  	$('#content_cnt div[onclick]').hover( function(){ $(this).addClass('cc_home_hover'); $('img.cc_img_fc', this).show(10);  },			// A mouseover
										  function(){ $(this).removeClass('cc_home_hover'); $('img.cc_img_fc', this).hide(10);  });		// A mouseout


	// CONTENT create nice links in H2
	$('#content_cnt H2 A').addClass('cc_invert');


	// MENU hover
	$('#menu_main A').hover( function(){   cc_hide_search(); $(this).addClass('cc_invert_hover'); // Mouseover
										   if ($(this).hasClass('cc_search')) { $('#menu_intro').hide(0); $('#menu_search').show(0); } else {  $('#menu_intro').html('<p class=cc_color>'+$(this).attr('rel')+'</p>'); $('#menu_intro').show(0); $('#menu_search').hide(0);  }
						               },			
					         function(){    // Mouseout
										   if (!$(this).hasClass('cc_search')) { $('#menu_intro').html(''); $(this).removeClass('cc_invert_hover'); }
									   });	

	// MENU SERACH BUTTON hover
	$('#form_search_submit').hover( function(){ $(this).addClass('form_search_button_hover'); },			// A mouseover
					                function(){ $(this).removeClass('form_search_button_hover');  });		// A mouseout


	// CONTENT inline links [+] hover
	$('#content_cnt A').hover( function(){ $('SPAN.cc_read_more',this).addClass('cc_invert_hover'); },			// A mouseover
					           function(){ $('SPAN.cc_read_more',this).removeClass('cc_invert_hover');  });		// A mouseout

	// CONTENT end of text links [+] hover
	$('#content_cnt A.cc_read_more').hover( function(){ $(this).addClass('cc_invert_hover'); },			// A mouseover
											function(){ $(this).removeClass('cc_invert_hover');  });	// A mouseout

	// CONTENT H2 links [+] hover
	$('#content_cnt H2 A').hover( function(){ $(this).addClass('cc_invert_hover'); },					// A mouseover
					              function(){ $(this).removeClass('cc_invert_hover');  });				// A mouseout


	// CONTENT PAGE HOVER LINKS
	$('.do_color_hover A').hover( function(){ $(this).addClass('cc_invert_hover'); },					// A mouseover
					              function(){ $(this).removeClass('cc_invert_hover');  });				// A mouseout



	// CONTENT LOGO hover
	$('#content_logo').hover( function(){ $(this).addClass('cc_logo_hover'); },							// A mouseover
					          function(){ $(this).removeClass('cc_logo_hover');  });					// A mouseout


	// CONTENT BUTTON hover
	$('.form_main_button').hover( function(){ $(this).addClass('cc_invert_hover'); },					// A mouseover
								  function(){ $(this).removeClass('cc_invert_hover');  });				// A mouseout

	
	/*LAST ITEM IN SITEMAP */
	$('#sitemap_holder li:last-child').addClass('sitemap_list_last'); 


	// MAC OS fix for inverse
	if ($.client.os=='Mac') {
		$('h1 .cc_invert').addClass('cc_invert_mac');
		$('h2 .cc_invert').addClass('cc_invert_mac');
		$('#menu_main A').addClass('cc_invert_mac');
		$('#content_cnt .cc_invert').addClass('cc_invert_mac');
		$('#content_cnt .cc_read_more').addClass('cc_invert_mac');
		if ($.client.browser=='Safari') { 
				$('#menu_search .form_search_text').addClass('form_search_text_mac_safari'); 
				$('#menu_search .form_search_button').addClass('form_search_button_mac_safari'); 

				$('#content_cnt .form_text').addClass('form_text_mac_safari'); 
				$('#content_cnt .form_button').addClass('form_button_mac_safari'); 
				$('#content_cnt .form_main_button').addClass('form_button_mac_safari');
		}
	} // close if

	
	// CONTENT ZOEKEN
	$('#qID').val(jCC_Input_Search);
	$('#qID').focus(function(){						if ($(this).val()==jCC_Input_Search) { $(this).val(''); }  });
	$('#qID').blur(function(){						if ($(this).val()=='') { $(this).val(jCC_Input_Search) }  	});
	$('#search_form_button').click(function(){		if ($('#qID').val()==jCC_Input_Search) { $('#qID').val(''); } $('#search_form').submit();   });


	// USE 2ND LAST: Column Balancer
/*
	var jHeightContent = $("#content_left_text").height()/2;
	jHeightContent = Math.round(jHeightContent);

	var jSplitHeight = 400;
	var jHasImage = $("#content_right_cnt .cc_img_wrapper").length;
	if (jHasImage>0) { jSplitHeight = 250; }

	if (jHeightContent>jSplitHeight) {
		$("#content_left_text").columnize({
			width : 324,
			buildOnce : true,
			dontsplit: "h1,p,li,ul,table,div",
			overflow : {
				id : "#content_right_text",
				height: jHeightContent,
				doneFunc : function(){ }
			}
		});
	}	// close if 
*/


	// USE LAST: CONTENT PAGES ONLY add grayscale image, we check for http in the url
	if (checkObject("content_left_text") || checkObject("content_right_text") || checkObject("content_full_text")) {
			$('#content_cnt img').each(function() { 
				var jSrc = $(this).attr('src');
				if ((jSrc.toLowerCase().indexOf('http://')==-1) && (jSrc.toLowerCase().indexOf('/media-files/')!==-1) && ($(this).hasClass('cc_img_bw')==false) && ($(this).hasClass('cc_img_fc')==false)) {
					$(this).wrap('<div class="cc_img_wrapper" />');
					$(this).parent("div.cc_img_wrapper").prepend($(this).clone().addClass('cc_img_fc'));
					$(this).addClass('cc_img_bw');
					jSrc = jSrc.replace(/.jpg/gi, "g.jpg");
					$(this).attr('src', jSrc);
				}
			});
	} // close if

	// CONTENT images hover
	$('#content_cnt .cc_img_wrapper').hover( function(){ $('img.cc_img_fc', this).show(10);  },			// A mouseover
								             function(){ $('img.cc_img_fc', this).hide(10);  });		// A mouseout	


 });	// close document-load.




