jQuery(document).ready(function () {

	Cufon.replace('.font', { hover: true , hoverables: { span: true } });

	Shadowbox.init({
		language:   "nl",
		players:["img","html","iframe"]
	});
	
	setTimeout("box_height()",1000);
	
	setTimeout("slider()",500);
	
	blog_title_width();
	
	get_map_link();
	
	footer_height();
	
	breadcrum();
	
	$('.datepicker').datepicker({
			changeMonth: true,
			changeYear: true,
			dateFormat: 'dd.mm.yy',
			yearRange: '-100:00'
		});
		
		$("#birth").change(function(){
				check_age();
		});
		
		$("#promotion-code").blur(function(){
				check_promotion();
		});
		

// end
});

function slider()
{

	jQuery('.move-right').cycle({ 
		fx: 'scrollRight', 
		delay: -100000
	});

}

function block_button()
{
	
	var check = jQuery("#age-check:checked").val();
	
	if( check == 1 )
		jQuery("#age-check-button").show();
	else
		jQuery("#age-check-button").hide();
	
}

function hide_things()
{
	
	jQuery("select, object, embed, canvas").addClass("hide");
	
}

function show_things(text)
{
	var day = $("#day").val();
	var month = $("#month").val();
	var year = $("#year").val();
	var age = 18;
	var mydate = new Date();
	mydate.setFullYear(year, month-1, day);

	var currdate = new Date();
	currdate.setFullYear(currdate.getFullYear() - age);
	if ((currdate - mydate) < 0 || ( day == '' || month == '' || year =='') ){
		alert(text);
		return false;
	}
	//return true;
	document.cookie = 'age=pass; expires=Thu, 1 Aug 2100 23:59:00 UTC; path=/'
	
	jQuery("select, object, embed, canvas").removeClass("hide");
	jQuery("#page-body").removeClass("block");
	jQuery("#age-block").hide("slow");
	
}


function get_map_link()
{

	jQuery(".glink").each(function() {
		var temp_var = jQuery(this).attr('id');
		if ( temp_var )
		{
			var temp = temp_var.split('_');
			var link = jQuery("#"+temp[1]+"_"+temp[2]+" .gmnoprint a").attr('href');
			jQuery("#look_"+temp[1]+"_"+temp[2]).attr( 'href' , link );
		}
	});
}

function GoogleMaps( lat , lng , name ){
    Shadowbox.open({
        player:     'html',
        content:    '',
        height:     600,
        width:      800,
        options:    {
            onFinish: function(item){
                if(GBrowserIsCompatible()){
                    var body = document.getElementById(Shadowbox.contentId());
                    var map = new GMap2(body);
                    map.setCenter(new GLatLng( lat , lng ), 10);

                    // add 10 markers to the map at random locations
                    var bounds = map.getBounds();
                    var southWest = bounds.getSouthWest();
                    var northEast = bounds.getNorthEast();
                    var lngSpan = northEast.lng() - southWest.lng();
                    var latSpan = northEast.lat() - southWest.lat();
                    
					var punkt  = new GLatLng( lat , lng );  
					var marker = new GMarker(punkt,{title: name});  
  
					map.addOverlay(marker);

                    // add some simple controls
                    map.addControl(new GSmallMapControl());
                    map.addControl(new GMapTypeControl());
                }
            }
        }
    });
}


function blog_title_width()
{
	
	var w1 = jQuery(".blog-box").width();
	var w2 = jQuery(".blog-box .blog-img").width();
	var w3 = w1 - w2 - 30;
	jQuery(".blog-box h3").width(w3);
	
}


function insert_map(in_html)
{
	
	jQuery(".wijn-box:first").parent("div").prepend( in_html );
	
}

function box_height()
{
	
	var WineHeight = 0;
	jQuery(".wijn-box-center, .wijn-box2-center").each(function ()
	{
	
		if ( jQuery(this).height() > WineHeight )
			WineHeight = jQuery(this).height();
			
			//alert(WineHeight);

	});
	
	jQuery(".wijn-box-center, .wijn-box2-center").height(WineHeight);
	
	var WineHeightP = 0;
	jQuery(".wijn-box-center p, .wijn-box2-center .txt").each(function ()
	{
	
		if ( jQuery(this).height() > WineHeightP )
			WineHeightP = jQuery(this).height();

	});
	
	jQuery(".wijn-box-center p, .wijn-box2-center .txt").height(WineHeightP);
	
}

function footer_height()
{
	
	var FoterHeight = 0;
	jQuery(".site_map").each(function ()
	{
	
		if ( jQuery(this).height() > FoterHeight )
			FoterHeight = jQuery(this).height();
			
			//alert(FoterHeight);

	});
	
	jQuery(".site_map").height(FoterHeight);
	
	var ftxt =  jQuery("#footer-txt").height();
	
	jQuery("#footer-txt").css( 'padding-top' , FoterHeight-ftxt );
		
}

function change_tip( func , modul_id , id , modul_title )
{
		
	$.get("/ajax/ajax.php5", { func: func, modul_id: modul_id , id: id, modul_title: modul_title},
	function(wynik){
				
		$("#"+modul_id).html(wynik);
		
	});
	
}

function change_tip2( func , rodzic , modul_id , id , modul_title )
{
		
	$.get("/ajax/ajax.php5", { func: func, rodzic: rodzic, modul_id: modul_id , id: id, modul_title: modul_title},
	function(wynik){
				
		$("#"+modul_id).html(wynik);
		
	});
	
}

function check_promotion()
{

	var code = jQuery("#promotion-code").attr('value');
	
	$.get("/ajax/ajax.php5", { func: 'code_nr', code_nr: code },
	function(wynik){
		
		if( wynik > 0 )
		{
			jQuery("#promotion-error").html('');
			jQuery("#promotion-id").attr( 'value' , wynik );
		}
		else
		{
			if( code != '' )
				jQuery("#promotion-error").html( 'Deze couponcode is onjuist. Controleer de couponcode en probeer opnieuw.' );
			jQuery("#promotion-id").attr( 'value' , '' );
		}
		//jQuery("#promotion-error").html(wynik);
		
	});

}

function get_map( id , lat , lng , name )     
{     
// tworzymy mapę
mapa = new GMap2(document.getElementById( id ));  
mapa.setCenter(new GLatLng( lat , lng ),10);  

// stworzenie markera  
var punkt  = new GLatLng( lat , lng );  
var marker = new GMarker(punkt,{title: name});  
  
// dodanie markera na mapę  
mapa.addOverlay(marker);

}

function IsEmailCorrect(email) {

  return email.match(/^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@([a-zA-Z0-9-]+\.)+([a-zA-Z]{2,3})$/)!=null;

}

function check_form( idk )
{
	
	var and_what = 0;
	
	jQuery(".check").each(function ( loop ) {
													
			//alert (jQuery(this).attr("type") + ' === ' + jQuery(this).val() );
			
			
			if( jQuery(this).val() == '' || ( jQuery(this).hasClass("email") && !IsEmailCorrect( jQuery(this).val() ) ) )
			{
				jQuery(this).addClass("error");
				and_what = 1;
			}
			else
			{
				jQuery(this).removeClass("error");
			}
			
	});
	
	if(and_what == 1)
	{
		alert("Vul de verplichte velden.");
		return false;
	}
	else
	{
		jQuery( "#"+idk ).submit();
	}
	
}

function check_age()
{

	var birth = jQuery("#birth").attr('value');
	
	$.get("/ajax/ajax.php5", { func: 'birth', birth: birth },
	function(wynik){
				
		if( wynik > 0 )
		{
			jQuery("#birth-error").html('');
			//jQuery("#register-form").attr( 'onsubmit' , 'return true;' );
			
		}
		else
		{
			jQuery("#birth-error").html( 'Je moet 18 jaar zijn om Club Salentein Member te mogen worden.' );
			//jQuery("#register-form").attr( 'onsubmit' , 'return false;' );
		}
		
	});

}

function breadcrum()
{

	var group = jQuery(".main_active .title").html();
	if( group )
		jQuery("#breadcrum").append( group + " &gt; " );
		
	var page = jQuery(".sub_active").html();
	if( page )
		jQuery("#breadcrum").append( page + " " );
		
	var page_top = jQuery("#topbar .active").html();
	if( page_top && ( group == '' ) )
		jQuery("#breadcrum").append( page_top + " " );
		
}




