$(document).ready(function(){

    // Simple fancybox
    $("a.fancybox, a.logoexamplelink").fancybox();

    if ($(window).width() > 680) {
        // YouTube
        $("a.youtube").click(function() {
        	console.log("clicked...");
        	$.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/'),
        		'type'			: 'swf',
        		'swf'			: {
        		   	'wmode'		: 'transparent',
        			'allowfullscreen'	: 'true'
        		}
        	});
        	return false;
        });
    }
    
    
    // Make external links
    $("a.external").attr("target","_blank");
    
    
    $("a.purchase_ticket").click(function(e){
        var arrNr = $(this).data("id");
        window.open("https://pay.ebillett.no/velg_antall.php?arrnr="+arrNr+"&p_id=123", "_blank", "location=0,menubar=0,toolbar=0,height=650,width=700");
        e.preventDefault();
    });
    
    /*$("nav a").click(function(e){
        var id = $(this).id.replace(/^_/, '')
        $("#maincontent").load("/kontakt?ajax");
        window.location.hash = stringTarget;
        return false;
    });*/
    
    /*function effectuateDeepLinking() {
        // Deep linking
        var hash = window.location.hash;
        hash = hash.replace(/^#/, '');
        $("#_" + hash ).trigger("click");
    }
    effectuateDeepLinking();*/
    
});



/* https://gist.github.com/901295 : JavaScript fix for the iOS viewport scaling bug */

// Rewritten version
// By @mathias, @cheeaun and @jdalton

(function(doc) {

	var addEvent = 'addEventListener',
	    type = 'gesturestart',
	    qsa = 'querySelectorAll',
	    scales = [1, 1],
	    meta = qsa in doc ? doc[qsa]('meta[name=viewport]') : [];

	function fix() {
		meta.content = 'width=device-width,minimum-scale=' + scales[0] + ',maximum-scale=' + scales[1];
		doc.removeEventListener(type, fix, true);
	}

	if ((meta = meta[meta.length - 1]) && addEvent in doc) {
		fix();
		scales = [.25, 1.6];
		doc[addEvent](type, fix, true);
	}

}(document));
