$(document).ready(function () {
    subMenu();
    cufonize();
    popUp('#popup', 'iframe');
    slideShowHome();
    slideShowPeople();
    tabs();
    hoverMaps();
    collapsePublications();
    //selectCategory();
    //inputWatermark();
    watermarks();
    contactSwitch();
    addInputs();
    addExternal();
    formUploads();
});

function formUploads() {
    $.each($(".upload ul li"), function () {
        var t = $(this);
        t.append('<a href="">Veld toevoegen</a>').hide();
        t.find('a').click(function () {
            $(this).parent().next().fadeIn(500);
            $(this).fadeOut(500);
            return false;
        })
    });
    $('.upload ul li:eq(0), .upload ul li:eq(1)').show();
    $('.upload ul li:eq(0) a, .upload ul li:eq(9) a').hide();
}

function addExternal() {
    $('a[rel*=external]').click(function () {
        window.open($(this).attr('href'));
        return false;
    });
}

function addInputs() {
    var i = 1;
    $('a.add').click(function () {

        $('<div class="uploadFile"><input type="file" runat="server" id="inputFile' + i + '" size="20" /></div>')
	    .animate({ opacity: "show" }, "slow")
	    .appendTo('.upload');
        i++;
    });

}

function contactSwitch() {
    if ($('#denhaag').hasClass('selected')) {
        $('div.route').hide();
        $('div#routeDenhaag').show();
    }
    else {
        $('div.route').hide();
        $('div#routeRotterdam').show();
    }
    $('div.#denhaag').click(function () {
              if($('#denhaag').hasClass('selected')) {
                     $('div.route').hide();
                     $('div#routeDenhaag').show();
              }
              else {
                     $('div.contact').removeClass('selected');
                     $('#denhaag').addClass('selected');
                     $('div.route').hide();
                     $('div#routeDenhaag').show();
              }
        reCreateMarkers(0);
    });
    $('div.#rotterdam').click(function () {
        if ($('#rotterdam').hasClass('selected')) {
            $('div.route').hide();
            $('div#routeRotterdam').show();
        }
        else {
            $('div.contact').removeClass('selected');
            $('#rotterdam').addClass('selected');
            $('div.route').hide();
            $('div#routeRotterdam').show();
        }
        reCreateMarkers(1);
    });
}

function subMenu() {
	$("#additionalMenu li").each(function(){
		if($(this).has("ul").length){
          
          	$(this).addClass('folder');
          
          }
    })
}
function inputWatermark() {

    if ($('.watermarked').watermark) {
        $('.watermarked').watermark('watermark');
    }
}

//function selectCategory() {
//	$("#categories li").click(function (e) {
//	e.preventDefault();
//      $(this).toggleClass('selected');
//    });
//}

function collapsePublications() {
    if ($('ul#publications').ttCollapse) {
        $('ul#publications').ttCollapse({
            openText: "Alle publicaties tonen",
            closeText: "Alle publicaties verbergen"
        });
    }
}

function watermarks() {
    $.each($('.watermarks'), function () {
        $(this).attr('rel', $(this).val() );

        $(this).blur(function () {
            if ($(this).val() == '') {
               $(this).val($(this).attr('rel'));
            };
        });
        $(this).click(function () {
            if( $(this).val() == $(this).attr('rel') ) $(this).val('');
        });
    });
};

function cufonize() {
    
    Cufon.replace(['#quoteTitle, .quoteTitle'], {
        fontFamily: 'Univers',
        fontWeight: '700',
        hover: true
    });
    Cufon.replace(['.homeTitle, .about p, #quoteSubTitle, .quoteSubTitle'], {
        fontFamily: 'Univers',
        fontWeight: '300',
        hover: true
    });

}

function popUp(id, type) {
    if ($(id).fancybox) {
        $(id).fancybox({
		    'width'				: 670,
		    'height'			: 357,
		    'autoScale'			: false,
		    'scrolling'         : 'no',
            'hideOnContentClick': false,
		    'type'				: type
	    });
    }
}

function slideShowPeople() {
    if ($('.slideshow ul').cycle) {
        $('.slideshow ul').cycle({
            fx: 'fade',
            random: 1
        });
    }
}

function slideShowHome() {
    if ($('.slideshow ul').cycle) {
        $('.slideshowHome ul').before('<ul id="nav">').cycle({
            fx: 'fade',
            pager: '#nav',

            // callback fn that creates a thumbnail to use as pager anchor
            pagerAnchorBuilder: function (idx, slide) {
                return '<li><a href="#"><span>' + idx + '</span></a></li>';
            }
        });

        $('ul#nav li a').click(function () {
            $('div.slideshow').cycle('pause');
        });
    }
}

function tabs() {
    if ($('#tabs').tabs) {
        $('#tabs').tabs();
        $("#tabs > ul > li").each(function (i) {
            $(this).removeClass("ui-state-disabled");

        });
    }
}
function hoverMaps() {

$("a.gmaps").hover(

	function() {
		$(this).children('span.overlay').stop().show();
		},
	function() {
		
		$(this).children('span.overlay').stop().hide();
	});
}


