// JavaScript Document

$.noConflict();
jQuery(document).ready(function($) {
	$(function(){

		/* CTAs */
		$('.CTA').each(function(){
						var cpg = $('body').attr('id');
						cpg = cpg.split('_');
						var tpag = $(this).attr('href');
						var pos = $(this).attr('rel');
						/* if we have subpages &|or trailling / */					
						tpag = tpag.split('/');
						if( tpag[ (tpag.length) -1 ] == "" ){tpag = tpag[ (tpag.length) -2 ];}else{tpag = tpag[ (tpag.length) -1];}

						tracker = "_gaq.push(['_trackEvent', '"+tpag+"', '"+cpg[1]+"', 'CTA"+pos+"']);";
						$(this).attr('onclick',tracker);
					});
		
		/* remove CTA realistaties from it's page*/
		if($('body').attr('id') == 'body_realisaties')	{	$('#CTA-rel').remove();		}
		/* remove CTA contact from page offerte*/
		if($('body').attr('id') == 'body_offerte')	{	$('#CTA-ctc').remove();		}
		/* remove CTA contact from bevestiging-contact */
		if($('body').attr('id') == 'body_bevestiging-contact')	{	$('#CTA-ctc').remove();		}
		/* remove CTA offerte in sidebar from bevestiging-offerte */
		if($('body').attr('id') == 'body_bevestiging-offerte')	{	$('.content_41').remove();		}
		/* remove CTA offerte in sidebar from bevestiging-offerte */
		if($('body').attr('id') == 'body_offerte')	{	$('.content_41').remove();		}



		/* mini-gallery banner home */ 
		$('#si li a').click(function(event){
									event.preventDefault();
									$('#si').find('li').removeClass('active');
									$(this).parent('li').addClass('active');
									
									im = $(this).attr('href');
									path = $('#bi').attr('src');
									path = path.split('/');
									path[ (path.length)-1 ] = im;
									path = path.join('/');
									$('#bi').fadeOut('fast', function(){ $('#bi').attr('src', path ).fadeIn('fast');});
					});
		/* auto-start & loop */
		var t = setInterval(function(){
					var tot =  $('#si li').length;
					var crt = 0, x = 0;
					$('#si li').each( function(){
											if( $(this).hasClass('active') ) {crt = x; }else{ x++; };
										});
					if(crt != tot-1){crt++;}else{crt =0;}
					$('#si li').eq(crt).find('a').trigger('click');
 				},7500);



		/* contact textarea default values */
		var def_val_c = "Stel hier uw vraag";
		$('#body_contact textarea').focus(function(){
									   if($(this).val() == def_val_c)
									   { $(this).val('');}
					   });
		$('#body_contact textarea').blur(function(){
								   if($.trim($(this).val()) == "")
								   { $(this).val(def_val_c);}
					   });
		/* offerte textarea default values */
		var def_val_o = "Geef hier extra informatie over uw specifieke noden en  wensen voor een offerte op maat";
		$('#body_offerte textarea').focus(function(){
									   if($(this).val() == def_val_o)
									   { $(this).val('');}
					   });
		$('#body_offerte textarea').blur(function(){
								   if($.trim($(this).val()) == "")
								   { $(this).val(def_val_o);}
					   });


		/* realisaties carrousel */
		
		
		
		if( $('body').attr('id') == 'body_realisaties')
		{
		
			var galleries = $('.ad-gallery').adGallery( {cycle: true,loader_image:'./themes/de-bestrater/layout/images/realisaties/controls/loader.gif',
														   slideshow: { enable: false}
													   });
			
		}
		
		
		if( $('body').attr('id') == 'body_realisaties2')
		{

					function mycarousel_initCallback(carousel) {
						jQuery('.jcarousel a').bind('click', function() {
							
							carousel.scroll(jQuery.jcarousel.intval($(this).attr('rel'))); /* scroll */
							$('.jcarousel a').removeClass('active');/* remove active */
							$(this).addClass('active'); /* add active */
					
							if($('#bgi').attr('src') != 'themes/de-bestrater/layout/images/realisaties/'+$(this).attr('href') )
							{
								$('#bgi').attr('src', 'themes/de-bestrater/layout/images/realisaties/'+$(this).attr('href') )
								
							}
					
							return false;
						});
					}	
						
					
					
					function mycarousel_itemFirstInCallback(carousel, item, idx, state) {
						id = idx-1;
						b = 'themes/de-bestrater/layout/images/realisaties/'+$('.jcarousel li').eq(id).find('a').attr('href');
						$('.jcarousel a').removeClass('active');/* remove active */
						$('.jcarousel li').eq(id).find('a').addClass('active'); /* add active */

						$('#bgi').attr('src',b);
						
					};	
						
						jQuery('#mycarousel').jcarousel({
							vertical: true,
							scroll: 1,
						//	wrap:'circular',
							initCallback: mycarousel_initCallback,
							itemFirstInCallback:  mycarousel_itemFirstInCallback
						});

		}
		/* / realisaties carrousel */




	});
});
