
$(document).ready(function() {
	$(".lightboxitem").lightBox({fixedNavigation:true});
	$('.slideshow').cycle({
		speed:  300,
		fx: 'fade',
		prev: '.btn_prev', 
		next: '.btn_next', 
		timeout: 0
	});
	
	$('#container_portfoliopreview_wrapper').cycle({ 
		   fx:     'scrollLeft', 
			speed:   2000,
			timeout: 2000, 
			pause:   1 
	});
	
	//$(".slideshow, .shadow_overlay").mousewheel(function(event, delta) {
	//	event.preventDefault(); // hou de pagina tegen
	//	
	//	if(delta==1) {
	//		$(".btn_prev").trigger('click');
	//	} else {
	//		$(".btn_next").trigger('click');
	//	}
	//	
	//	return false;
	//});
	
	
	//margin afbeelding
	$(".blog_container").find('img').each( function() {
	
		var sAlign = $(this).attr("align");
	
		if (sAlign == "left") {
			$(this).css("border-right","15px solid #FFF");
		} else if (sAlign == "right"){
			$(this).css("border-left","15px solid #FFF");
		} else {
			$(this).attr("align","left");
			$(this).css("border-right","15px solid #FFF");	
		}
	
	});
	
	
	
	
});	


 function getURLRedirect(){
         //document.location.href ="http://wesensit.nl/valentijn";
	 var url = "http://wesensit.nl/valentijn"; 
	$(location).attr('href',url); 

    }



// text size
function resizeText(size) {
	$("#content_center").css("font-size",size + "pt");
	
	return false;
}

// Functie voor het afhandelen van de nieuwsbrief aan- / afmeld knop
function doNewsletter(inAction) {
	// We gaan de ajax aanvraag versturen
	$.ajax({
		url: "/ajax/newsletter",
		type: "POST",
		data: { action: inAction, email: $("input[name='newsletter_email']").val(), name: $("input[name='newsletter_name']").val(), company: $("input[name='newsletter_company']").val() },
		success: function(msg) {
			if(msg.substring(0, 2) == 'OK')
			{
				msg = msg.substring(3);
				alert(msg);
				$("input[name='newsletter_email']").val(eval("defaultValue.newsletter_email"));
			} else {
				alert(msg);
			}
		}
	});
}

// slider
var timeout = 300;
var closetimer = 0;
var ddmenuitem = 0;

function jsddm_open()
{	jsddm_canceltimer();
	jsddm_close();
	ddmenuitem = $(this).find('ul').eq(0).css('visibility', 'visible');
	
	$(this).find('a.top').addClass('selected');
}

function jsddm_close()
{
	if(ddmenuitem) {
		ddmenuitem.css('visibility', 'hidden');
		
		$("#header_dropdown").find('a.top').removeClass('selected');
	}
}

function jsddm_timer()
{
	closetimer = window.setTimeout(jsddm_close, timeout);
}

function jsddm_canceltimer()
{	if(closetimer)
	{	window.clearTimeout(closetimer);
		closetimer = null;}}

$(document).ready(function()
{
	$('#header_dropdown > li').bind('mouseover', jsddm_open);
	$('#header_dropdown > li').bind('mouseout',  jsddm_timer);
});

document.onclick = jsddm_close;


// array of object omzetten naar een json string.
function array2json(arr) {
    var parts = [];
    var is_list = (Object.prototype.toString.apply(arr) === '[object Array]');

    for(var key in arr) {
    	var value = arr[key];
        if(typeof value == "object") { //Custom handling for arrays
            if(is_list) parts.push(array2json(value)); /* :RECURSION: */
            else parts[key] = array2json(value); /* :RECURSION: */
        } else {
            var str = "";
            if(!is_list) str = '"' + key + '":';

            //Custom handling for multiple data types
            if(typeof value == "number") str += value; //Numbers
            else if(value === false) str += 'false'; //The booleans
            else if(value === true) str += 'true';
            else str += '"' + escape(value) + '"'; //All other things
            // :TODO: Is there any more datatype we should be in the lookout for? (Functions?)

            parts.push(str);
        }
    }
    var json = parts.join(",");
    
    if(is_list) return '[' + json + ']';//Return numerical JSON
    return '{' + json + '}';//Return associative JSON
}


// isnumeric
function IsNumeric(sText)
{
	var ValidChars = "0123456789";
	var IsNumber=true;
	var Char;
	
	for (i = 0; i < sText.length && IsNumber == true; i++) 
	{ 
		Char = sText.charAt(i); 
		if (ValidChars.indexOf(Char) == -1) 
		{
			IsNumber = false;
		}
	}
	return IsNumber;
}

/** Content filteren op youtube objecten **/
$(document).ready(function() {
	$("object").each(function() {
			if($(this).attr('data').indexOf("youtube.com") > 0) {
				var youtubeImg = $.ajax({url: "/ajax/ajax_content_front", type: "GET", data: {action: "ajax_content_front", functie: "getYoutube", url: $(this).attr('data')}, async: false}).responseText;
				var naampje = (new Date()).getTime();
				
				$(this).attr("id",naampje);
				$(this).wrap('<div id="container_' + naampje + '" style="height: ' + $(this).attr('height') + 'px; width: ' + $(this).attr('width') + 'px;" />');
				$(this).attr('wmode','opaque').css('display','block').css('position','absolute');
				
				$(this).after('<div onclick="changeFlash(\''+naampje+'\')" class="' + naampje + '" style="' + $(this).attr('style') + '; overflow: hidden; position: absolute; background: url(\'' + youtubeImg + '\'); height: ' + $(this).attr('height') + 'px; width: ' + $(this).attr('width') + 'px;" border="0" ><div style="height: 100%; width: 100%; background: url(/images/youtube_play.png) center no-repeat;"></div></div>');
				$(this).css('visibility','hidden');
			}
	});
	
	
	$("#valentijns_header").attr('alt', 'Doe mee');
	$("#valentijns_header").attr('title', 'Doe mee');
	$("#valentijns_header").css('cursor', 'pointer');
	
	
	
});
// Flash image omzetten naar flash movie
function changeFlash(naampje) {
	$("#"+naampje).children().each( function() {
		$(this).attr('value',($(this).attr('value') + '&autoplay=1'));
		
		//alert($(this).attr('value'));
	});
	$("#"+naampje).attr('data',($("#"+naampje).attr('data')+'&autoplay=1'));
	$("."+naampje).css('visibility','hidden');
	$("#"+naampje).css('visibility','visible');
}


// roterende bloemen
var ctx = null;
var can = null;

// bloem instellingen
var flower_position = [ [380,100], [310,200], [230,50], [1350,640], [1230,730], [1380,780] ]; // [x,y]
var flower_rotation = [350, 300, 30, 0, 0, 0];
var flower_scale = [0.6, 0.4, 0.9, 0.4, 0.9, 0.6];
var flower_speed = [0.4, 0.8, 0.1, 0.8, 0.1, 0.4];
var flower_opacity = [0.3, 0.3, 0.3, 0.6, 0.3, 0.4];

//window.onload = initCanvas;

function initCanvas() {
	
	// canvas geforceerd naar de viewport schalen
	$("#canvas_flowers").attr('width', $(window).width()).attr("height", $(window).height());

	// canvas ophalen
	can = document.getElementById('canvas_flowers');
	if(can) {
		if($.browser.msie && parseInt($.browser.version.slice(0, 1) ) < 9) {
			$('body').css("background-image", "url(../images/background_fix.png)");
			$('body').css("background-position", "top center");
			$('body').css("background-color", "#658bca");
			
		} else {		
			ctx = can.getContext("2d");
			draw_flowers();
			$("#canvas_flowers").fadeIn(3000);
		}
	}
};



function draw_flowers() {
	ctx.clearRect(0, 0, $(window).width(), $(window).height());
	
	for(var i=0; i<flower_position.length; i++) {
		ctx.save();  
		ctx.translate(flower_position[i][0], flower_position[i][1]);
		
		flower_rotation[i] += flower_speed[i];
		if(flower_rotation[i]==360) flower_rotation[i] = 0;
		
		ctx.rotate((flower_rotation[i]*(Math.PI/180))); // Rotate 45 degrees
		var t = -177*flower_scale[i];
		ctx.translate(-177*flower_scale[i], -177*flower_scale[i]);
		
		ctx.scale(flower_scale[i], flower_scale[i]); 
		ctx.beginPath();
		ctx.moveTo(242.3, 105.8);
		ctx.bezierCurveTo(247.6, 103.8, 264.1, 98.9, 272.8, 98.9);
		ctx.bezierCurveTo(284.9, 98.9, 297.2, 100.8, 309.3, 104.7);
		ctx.bezierCurveTo(318.5, 107.7, 327.0, 111.8, 334.6, 116.6);
		ctx.lineTo(352.7, 127.7);
		ctx.lineTo(344.8, 147.4);
		ctx.bezierCurveTo(341.3, 156.2, 336.8, 164.9, 330.8, 173.2);
		ctx.bezierCurveTo(318.6, 190.0, 296.7, 199.5, 276.5, 206.4);
		ctx.bezierCurveTo(276.5, 206.4, 270.8, 208.2, 260.1, 210.3);
		ctx.bezierCurveTo(266.4, 218.8, 270.7, 225.1, 270.7, 225.1);
		ctx.bezierCurveTo(283.0, 243.6, 294.7, 266.5, 294.7, 287.8);
		ctx.bezierCurveTo(294.7, 297.5, 293.4, 306.9, 291.3, 315.6);
		ctx.lineTo(286.3, 336.3);
		ctx.lineTo(265.1, 334.9);
		ctx.bezierCurveTo(255.8, 334.3, 246.1, 332.6, 236.4, 329.4);
		ctx.bezierCurveTo(216.9, 323.1, 200.1, 304.9, 187.0, 287.7);
		ctx.lineTo(186.2, 286.6);
		ctx.bezierCurveTo(186.2, 286.6, 182.7, 281.7, 177.5, 272.2);
		ctx.bezierCurveTo(171.3, 280.7, 166.6, 286.7, 166.6, 286.7);
		ctx.lineTo(165.7, 287.7);
		ctx.bezierCurveTo(152.5, 304.9, 135.8, 323.1, 116.3, 329.4);
		ctx.bezierCurveTo(106.6, 332.6, 96.9, 334.3, 87.5, 334.9);
		ctx.lineTo(66.3, 336.3);
		ctx.lineTo(61.3, 315.6);
		ctx.bezierCurveTo(59.2, 306.9, 57.9, 297.5, 57.9, 287.8);
		ctx.bezierCurveTo(57.9, 266.5, 69.6, 243.6, 82.0, 225.1);
		ctx.bezierCurveTo(82.0, 225.1, 86.3, 218.8, 92.5, 210.3);
		ctx.bezierCurveTo(81.8, 208.2, 76.1, 206.4, 76.1, 206.4);
		ctx.bezierCurveTo(56.0, 199.5, 34.1, 190.0, 21.9, 173.2);
		ctx.bezierCurveTo(15.9, 164.9, 11.3, 156.2, 7.8, 147.4);
		ctx.lineTo(0.0, 127.7);
		ctx.lineTo(18.0, 116.6);
		ctx.bezierCurveTo(25.7, 111.8, 34.1, 107.7, 43.4, 104.7);
		ctx.bezierCurveTo(55.4, 100.8, 67.7, 98.9, 79.8, 98.9);
		ctx.bezierCurveTo(88.5, 98.9, 98.9, 102.4, 106.6, 105.1);
		ctx.bezierCurveTo(114.3, 107.8, 121.6, 110.8, 121.6, 110.8);
		ctx.lineTo(123.5, 95.5);
		ctx.bezierCurveTo(124.4, 74.6, 127.8, 51.3, 139.7, 34.9);
		ctx.bezierCurveTo(145.7, 26.6, 152.5, 19.6, 159.7, 13.6);
		ctx.lineTo(176.0, 0.0);
		ctx.lineTo(192.2, 13.8);
		ctx.bezierCurveTo(199.0, 19.6, 205.6, 26.4, 211.3, 34.3);
		ctx.bezierCurveTo(223.1, 50.6, 226.6, 74.0, 227.5, 95.0);
		ctx.lineTo(228.3, 111.4);
		ctx.bezierCurveTo(228.3, 111.4, 236.9, 107.8, 242.3, 105.8);
		ctx.closePath();
		ctx.fillStyle = "rgba(255, 255, 255, "+flower_opacity[i]+")";
		ctx.fill();
		
		ctx.restore();
	}
	
	var t = setTimeout("draw_flowers()",75);
}




