//Prepare for HTML5
document.createElement("article");
document.createElement("footer");
document.createElement("header");
document.createElement("hgroup");
document.createElement("nav");
document.createElement("menu");


//Online model check single
$.ajax({
    cache: false,
    success: function(data) {
        var online = new Array();
        
        $.each(data.model, function(key, val) {
            online.push(val.naam);
        });

        var model = $('h1 span').text().toLowerCase();

        if($.inArray(model, online) > -1) {
            $("#status").addClass("online");
        }else{
            $("#status").addClass("offline");
        }
    },
    url: base_url + 'online.json'
});

//Online model check multi
$.ajax({
    cache: false,
    success: function(data) {
        var online = new Array();
        
        $.each(data.model, function(key, val) {
            online.push(val.naam);
        });

        $('.buttonbar').each(function(index) {
            var model = $(this).children('strong').text().toLowerCase();
            
            if($.inArray(model, online) > -1) {
                $(this).children(".status").addClass("online");
                $(this).children(".status").attr("title", "Online");
            }else{
                $(this).children(".status").addClass("offline");
                $(this).children(".status").attr("title", "Offline");
            }
        });
    },
    url: base_url + 'online.json'
});

//Preview
$(document).ready(function() {
    $("a#play-flv-video").fancybox({
        'scrolling': false,
        'titleShow': false,
        'onStart'  : function() {
            $("#flv-player").show();
            
            //Sidebar model preview
            var model = $('.mcontent strong').text().toLowerCase();
            
            $f("flv-player",
                 base_url + "assets/swf/flowplayer-3.2.7.swf",
                 "http://" + model + ".islive.nl/multimedia/promotie/" + model + "_promotie.flv");
        },
        'onClosed'  : function() {
            $("#flv-player").hide();
            $f().unload();
        }
    });

    $("a[rel=gallery]").fancybox({
        'transitionIn': 'none',
        'transitionOut': 'none',
        'titlePosition': 'over',
        'titleFormat': function (title, currentArray, currentIndex, currentOpts) {
            return '<span id="fancybox-title-over">Foto ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>'
        }
    });
});

//External links rel=""
function externalLinks() {
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		if (
			anchor.getAttribute("href") && (
			anchor.getAttribute("rel") == "external" ||
			anchor.getAttribute("rel") == "external nofollow" ||
			anchor.getAttribute("rel") == "nofollow external" )
			)
		anchor.target = "_blank";
	}
}

jQuery(document).ready(function() {
	externalLinks();
});
