var email_check = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
var string_check = /^([A-Za-z0-9_\-\. ])+$/;
var tel_check = /^([0-9_\+\-\. ])+$/;
var geb_check = /^([0-9]{2}-[0-9]{2}-[0-9]{4})+$/;

function showMenu(id)
{
    if (id)
    {
        $('#main_menu_' + id).show();
    }

    $('li.maintab').removeClass('selected');
    $('#maintab' + id).addClass('selected');
}
function hideMenu()
{
    $('div.mainmenu').hide();
    $('li.maintab').removeClass('selected');
}

function blogLike(type)
{
    $('#liketype').val(type);
    var loading = $("#like").busyBox({spinner: '<img src="/images/layout/ajax-loader.gif" />'});

    $.ajax({type: "POST", url: "/ajax/bloglike.html", data: $("#blogLikeForm").serialize(), success: function(data, textStatus, XMLHttpRequest)
    {
        $("#bloglike").html(data).fadeIn('fast');
    }, complete: function complete(XMLHttpRequest, textStatus)
        {
            loading.busyBox('close');
        }
    });

    return false;
}

function showMoreBlogItems(start)
{
    var loading = $("#homepageBlogItems").busyBox({spinner: '<img src="/images/layout/ajax-loader.gif" />'});

    $.ajax({url: "/ajax/" + start + "/blog_items.html", success: function(data, textStatus, XMLHttpRequest)
    {
        $("#homepageBlogItems").html(data).fadeIn('fast');
    }, complete: function complete(XMLHttpRequest, textStatus)
        {
            loading.busyBox('close');
        }
    });

    return false;
}

function addComment()
{
    sw = true;

    name = trim($('#name').val());
    email = trim($('#email').val());
    comment = trim($('#comment').val());

    if (name == '' || name == 'Naam (verplicht)')
    {
        alert('Je hebt geen naam ingevuld');
        sw = false;
    }
    else if (email == '' || email == 'Email (verplicht)')
    {
        alert('Je hebt geen e-mail ingevuld');
        sw = false;
    }
    else if (comment == '' || comment == 'Typ hier je reactie...')
    {
        alert('Je hebt geen reactie ingevuld');
        sw = false;
    }

    if (sw)
    {
        var loading = $("#commentsList").busyBox({spinner: '<img src="/images/layout/ajax-loader.gif" />'});

        $.ajax({type: "POST", url: "/ajax/comment/add.html", data: $("#postComment").serialize(), success: function(data, textStatus, XMLHttpRequest)
        {
            $("#commentsList").html(data).fadeIn('fast');
        }, complete: function complete(XMLHttpRequest, textStatus)
            {
                loading.busyBox('close');
            }
        });
    }
    return false;
}

$(document).ready(function(){

    $("div.zoomIn div div").hover(function() {
    	$(this).css({'z-index' : '10'}); /*Add a higher z-index value so this image stays on top*/
    	$(this).find('img').addClass("hover").stop() /* Add class of "hover", then stop animation queue buildup*/
    		.animate({
    			marginTop: '-110px', /* The next 4 lines will vertically align this image */
    			marginLeft: '-110px',
    			top: '50%',
    			left: '50%',
    			width: '174px', /* Set new width */
    			height: '174px', /* Set new height */
    			padding: '20px'
    		}, 200); /* this value of "200" is the speed of how fast/slow this hover animates */

    	} , function() {
    	$(this).css({'z-index' : '0'}); /* Set z-index back to 0 */
    	$(this).find('img').removeClass("hover").stop()  /* Remove the "hover" class , then stop animation queue buildup*/
    		.animate({
    			marginTop: '0', /* Set alignment back to default */
    			marginLeft: '0',
    			top: '0',
    			left: '0',
    			width: '100px', /* Set width back to default */
    			height: '100px', /* Set height back to default */
    			padding: '5px'
    		}, 400);
    });
});

$(document).ready(function(){
   $.PeriodicalUpdater({
      url : '/ajax/current/playlist.html'
   },
   function(data){
      $('#currentPlaylist').html(data);
   });
//
//   $(window).scroll(function(){
//        if  ($(window).scrollTop() > ($(window).height()))
//        {
//           //alert($(window).scrollTop() + ' - ' + $(window).height());
//        }
//    });
})

$(document).ready(function(){
    $(".youtube").click(function() {
	   $.fancybox({
			'padding'		: 0,
			'autoScale'		: false,
			'transitionIn'	: 'none',
			'transitionOut'	: 'none',
			'title'			: this.title,
			'width'		    : 680,
			'height'		: 495,
			'href'			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/') + '&autoplay=1',
			'type'			: 'swf',
			'swf'			: {
                'wmode'		       : 'transparent',
				'allowfullscreen'  : 'true',
			'overlayShow': true,
			'overlayOpacity' : 1,
			'overlayColor' : '#ff0000'
			}
		});
	    return false;
    });
    $(".vimeo").click(function() {
	   $.fancybox({
			'padding'		: 0,
			'autoScale'		: false,
			'transitionIn'	: 'none',
			'transitionOut'	: 'none',
			'title'			: this.title,
			'width'		    : 680,
			'height'		: 495,
			'href'			: this.href = this.href.replace(new RegExp("([0-9])","i"),'moogaloop.swf?clip_id=$1') + '&autoplay=1',
			'type'			: 'swf',
			'swf'			: {
			   	'wmode'		        : 'transparent',
				'allowfullscreen'	: 'true'
			}
		});
	    return false;
    });
});

function requestHit(hitid)
{
    $('a.req_hit').removeClass('selected');
    $('#req_hit_' + hitid).addClass('selected');

    $("#reqhitid").val(hitid);
    return false;
}

function checkContactForm()
{
    if ($('#name').val() == '' || $('#name').val() == 'Naam (verplicht)' || string_check.test($('#name').val()) == false)
    {
        alert('Je hebt geen naam ingevuld!');
        return false;
    }
    if ($('#email').val() == '' || $('#email').val() == 'Email (verplicht)' || email_check.test($('#email').val()) == false)
    {
        alert('Je hebt geen email opgegeven!');
        return false;
    }
    if ($('#phone').val() == '' || $('#phone').val() == 'Telefoonnummer (verplicht)' || tel_check.test($('#phone').val()) == false)
    {
        alert('Je hebt geen telefoonnummer opgegeven!');
        return false;
    }
    if ($('#comment').val() == '' || $('#comment').val() == 'Typ hier je vraag...')
    {
        alert('Je hebt geen opmerking opgegeven!');
        return false;
    }

    return true;
}

function checkThemeForm()
{
    if ($('#firstname').val() == '' || $('#firstname').val() == 'Voornaam *' || string_check.test($('#firstname').val()) == false)
    {
        alert('Je hebt geen voornaam ingevuld!');
        return false;
    }
    if ($('#surname').val() == '' || $('#surname').val() == 'Achternaam *' || string_check.test($('#surname').val()) == false)
    {
        alert('Je hebt geen achternaam opgegeven!');
        return false;
    }
    if ($('#birthday').val() == '' || $('#birthday').val() == 'Geboortedatum (dd-mm-jjjj) *' || geb_check.test($('#birthday').val()) == false)
    {
        alert('Je hebt geen geboortedatum opgegeven!');
        return false;
    }
    if ($('#adress').val() == '' || $('#adress').val() == 'Adres *' || string_check.test($('#adress').val()) == false)
    {
        alert('Je hebt geen adres opgegeven!');
        return false;
    }
    if ($('#zipcode').val() == '' || $('#zipcode').val() == 'Postcode (1111 AA) *' || string_check.test($('#zipcode').val()) == false)
    {
        alert('Je hebt geen postcode opgegeven!');
        return false;
    }
    if ($('#city').val() == '' || $('#city').val() == 'Woonplaats *' || string_check.test($('#city').val()) == false)
    {
        alert('Je hebt geen woonplaats opgegeven!');
        return false;
    }
    if ($('#phone').val() == '' || $('#phone').val() == 'Telefoonnummer *' || tel_check.test($('#phone').val()) == false)
    {
        alert('Je hebt geen telefoonnummer opgegeven!');
        return false;
    }
    if ($('#email').val() == '' || $('#email').val() == 'Email *' || email_check.test($('#email').val()) == false)
    {
        alert('Je hebt geen e-mailadres opgegeven!');
        return false;
    }
    if ($('#comment').val() == '' || $('#comment').val() == 'Vertel WILD FM en onze bezoekers waarom juist jij deze prijs zou moeten winnen. Zorg voor een leuke motivatie!')
    {
        alert('Je hebt geen motivatie opgegeven!');
        return false;
    }
    if ($('#file').val() == '')
    {
        alert('Je hebt geen foto geselecteerd!');
        return false;
    }
    if ($('#conditions').attr('checked') == false)
    {
        alert('Je bent niet akkoord gegaan met de algemene voorwaarden!');
        return false;
    }

    return true;
}

function requestHitForm()
{
    if ($('#reqhitid').val() == '')
    {
        alert('Je hebt geen hit geselecteerd!');
        return false;
    }
    if ($('#reqhitname').val() == '' || $('#reqhitname').val() == 'Je naam')
    {
        alert('Je hebt geen naam opgegeven!');
        return false;
    }
    if ($('#reqhitphone').val() == '' || $('#reqhitphone').val() == 'Je telefoonnummer')
    {
        alert('Je hebt geen telefoonnummer opgegeven!');
        return false;
    }
    if ($('#reqhitcomment').val() == '' || $('#reqhitcomment').val() == 'Reden...')
    {
        alert('Je hebt geen reden opgegeven!');
        return false;
    }

    var loading = $("#wildRequest").busyBox({spinner: '<img src="/images/layout/ajax-loader.gif" />'});

    $.ajax({type: "POST", url: "/ajax/request_hit.html", data: $("#requestHitForm").serialize(), success: function(data, textStatus, XMLHttpRequest)
    {
        $("#wildRequest").html(data).fadeIn('fast');
    }, complete: function complete(XMLHttpRequest, textStatus)
        {
            loading.busyBox('close');
        }
    });

    return false;
}

self.name = 'mainsite';

function openWindowplayer()
{
	window.open("/player.html","WILDFM","scrollbars=no,resizable=no,location=no,menubar=no,directories=no,status=no,width=847,height=621");
}

function trim(value)
{
    value = value.replace(/^\s+/,'');
    value = value.replace(/\s+$/,'');
    return value;
}
