// The next line enables jQuery IntelliSense in Visual Studio:
/// <reference path="/common/js/IntelliSense/jquery-1.3.1-vsdoc.js" />

$(document).ready(function() {
	
	
	$(".tweet").tweet({
		username: 'CpdeHout',
		count: 1,
		loading_text: 'loading tweets...'
	});
							
	
	jQuery(function(){
        var SelfLocation = window.location.href.split('?');
        switch (SelfLocation[1]) {
          case "justify_right":
            jQuery(".megamenu").megamenu({ 'justify':'right' });
            break;
          case "justify_left":
          default:
            jQuery(".megamenu").megamenu();
        }
      });
	
	
	
	$('a#show-gastenboek-formulier').click(function() {
  		$('#gastenboek-formulier').slideToggle('slow', function() {
    		// Animation complete.
  		});
	});
	
	
	$(".slideshow").cycle({
	    fx: 'fade', 
   		timeoutFn: calculateTimeout
	});
	
	function calculateTimeout(currElement, nextElement, opts, isForward) { 
	    var myTimeOut = 4000;
		var index = opts.currSlide; 
		
		return myTimeOut; 
	} 
	
	$("a.fancybox-toggle").fancybox({
        'hideOnContentClick': false,
        'frameWidth': 700,
        'frameHeight': 450,
        'padding': 5
    });
	
	$("a#single_2").fancybox({
		'zoomOpacity'			: true,
		'overlayShow'			: false,
		'zoomSpeedIn'			: 500,
		'zoomSpeedOut'			: 500
	});
	
	$("a#single_3").fancybox({
		'zoomOpacity'			: true,
		'overlayShow'			: false,
		'zoomSpeedIn'			: 500,
		'zoomSpeedOut'			: 500,
		'autoScale'				: false,
		'width'                 : 500
	});
	
	$("a.fancybox-iframe").each(function() {
      	w = $.parseQuery($(this).attr('href')).width * 1; /* Get the iframe width from the querystring of the link */
        h = $.parseQuery($(this).attr('href')).height * 1; /* Get the iframe height from the querystring of the link */
      	var showCloseButton = $(this).hasClass("fancybox-showCloseButton");
        var hideOnOverlayClick = $(this).hasClass("fancybox-hideOnOverlayClick");
        $(this).fancybox({
            'frameWidth': w
            , 'frameHeight': h
            , 'overlayShow': true
            , 'centerOnScroll': true
            , 'showCloseButton': showCloseButton
            , 'hideOnOverlayClick': hideOnOverlayClick
			, 'type': 'iframe'
        });
    });
		
	$("form").submit(function(){    
		$("button.hideSubmitButtonOnClick").attr('disabled', 'disabled');
	});
	
	
	$("a.show-act-text").click(function(){
		
		myId = this.id
		
		myIntroId = myId.replace("show-act-text", "act-intro");
		myTextId = myId.replace("show-act-text", "act-text");
		myLinkId = myId.replace("show", "hide");
		
		// hide
		$(this).hide();
		$("div#"+ myIntroId).hide();
		
		// show
		$("div#"+ myTextId).slideDown();
		$("a#"+ myLinkId).show();
		
	});
	
	$("a.hide-act-text").click(function(){
		
		myId = this.id
		
		myIntroId = myId.replace("hide-act-text", "act-intro");
		myTextId = myId.replace("hide-act-text", "act-text");
		myLinkId = myId.replace("hide", "show");
		
		// hide
		$(this).hide();
		$("div#"+ myTextId).slideUp();
		
		// show
		$("div#"+ myIntroId).show();
		$("a#"+ myLinkId).show();
		
	});
	
	
});




function insertMediaIdSetPreviewAndCloseFancyBox(MediaGuid, MediaId, HiddenInputName)
{
	
	// set input value
	objInputHidden = parent.document.getElementById(HiddenInputName);
	objInputHidden.value = MediaId;
	
	//show preview 
	parent.$("#mediaPreviewBox-"+ HiddenInputName).slideDown();
	
	//set image
	imagePath = "/_generated/media/250/"+ MediaGuid + ".jpg";
	objImage = parent.document.getElementById('mediaPreviewImage-'+ HiddenInputName);
	objImage.src = imagePath;
	
	//close
	parent.$.fn.fancybox.close();

}

function deleteInitialTextAndChangeColor(objInput)
{
	objInput.value = "";
	objInput.style.color = "#000000";
}

function confirmUrl(confirmText, newUrl)
{
	if (confirm(confirmText)) {
		
		window.location.href = newUrl;
		
	} else {
		// do nothing
	}
}



$.parseQuery = function(qs, options) {
    var q = (typeof qs === 'string' ? qs : window.location.search), o = { 'f': function(v) { return unescape(v).replace(/\+/g, ' '); } }, options = (typeof qs === 'object' && typeof options === 'undefined') ? qs : options, o = jQuery.extend({}, o, options), params = {};
    jQuery.each(q.match(/^\??(.*)$/)[1].split('&'), function(i, p) {
        p = p.split('=');
        p[1] = o.f(p[1]);
        params[p[0]] = params[p[0]] ? ((params[p[0]] instanceof Array) ? (params[p[0]].push(p[1]), params[p[0]]) : [params[p[0]], p[1]]) : p[1];
    });
    return params;
}


