function init_portfolio(standard) {
    var location = window.location.toString();
    var location_arr = location.split("#/", 2);
    if (location_arr.length > 1) {
        var cat_page = location_arr[1].split("/");
        var cat = cat_page[0];
        var page = 1;
        if (cat_page[1]) {
            page = cat_page[1]; 
        }
        
        generate_portfolio_items(cat, page);
    } else {
        generate_portfolio_items(standard, 1);
    }
    
}

function generate_portfolio_items(cat_id, page) {    
    //$("#portfolio").animate({"opacity": "0.2"}, 300);
    
    $("#portfolio").fadeOut(300);
    
    $.post("/includes/ajax_get_items.php", {
        cat_id: cat_id,
        page: page
    }, function (data) {
        $(".categorieen li").removeClass("current");
        
        $("#portfolio").html("");
        
        $(".categorieen li[title=" + data.cat_id + "]").addClass("current");
        
        //$("#portfolio").stop().css({"opacity": "1"});
        
        for(var i = 0; i < data.items.length; i++) {
            add_item(data.items[i]);
        }
        
        var blz = $("<div class='blz'></div>").appendTo("#portfolio");
        for (var i = 0; i < data.pages; i++) {
            var a = $("<a></a>").appendTo($(blz));
            $(a).html((i + 1));
            if (data.page == (i + 1)) {
                $(a).addClass("on");
            }
            $(a).attr("href", "/portfolio/#/" + data.url_base + "/" + (i + 1));
            $(a).click(function() {
                generate_portfolio_items(cat_id, $(this).html());
            });
        }
        
        $("#portfolio").fadeIn(300);
        //
        activate_items();
        
        Cufon.refresh('h2')('h3');
        Cufon.now();
        externalLinks();
        
    }, "json");
}

function add_item(object) {
    var item = $("<div class='item'></div>");
        var img = $("<img />").appendTo($(item));
        //$(img).addClass("shot");
        $(img).attr("src", object.img);
        
        var overlay = $("<div class='overlay'></div><img src='/images/launch.jpg' alt='' class='launch' />").appendTo($(item));
        
        var h2 = $("<h2></h2>").appendTo($(item));
        $(h2).html(object.titel);
        
        var desc = $("<div class='descr'></div>").appendTo($(item));
        
            $(desc).html(object.content);
        
            var h3 = $("<h3></h3>").prependTo($(desc));
            $(h3).html(object.sub_titel);
            
        var link_div = $("<div class='link'></span>").appendTo($(item));
        $(link_div).html(object.url_weergave);
        
        var link = $("<a></a>").appendTo($(item));
        $(link).attr("href", object.url);
		$(link).attr("rel", "external"); // bysieb
        
            var niks = $("<img />").appendTo($(link));
            $(niks).attr("src", "/images/nix.gif");
            
    $(item).appendTo("#portfolio");
}

// CUFON
Cufon.replace('h1');
Cufon.replace('h2');
Cufon.replace('h3');
Cufon.replace('h4');
Cufon.replace('.pfolio a', {hover: true});
Cufon.replace('.price', {hover: true});
Cufon.replace('#menu li a', {hover: true}); 
Cufon.replace('.price-pakketten', {hover: true});
Cufon.replace('.intro');

// SLIDES 



function activate_items() {
    // Portfolio items
	$(".item").hover(function() {
		$(this).find(".descr").stop().animate({ top: "0px" }, 200 );
		$(this).find(".link").css({ color: "#669900" });
		$(this).find(".launch").stop().animate({ top: "175px" }, 500 );
	} , function() { 
		$(this).find(".descr").stop().animate({ top: "-200px" }, 200 );
		$(this).find(".link").css({ color: "#666666" });
		$(this).find(".launch").stop().animate({ top: "0px" }, 200 );
	});
}
$(document).ready(function() {
	activate_items();
	
	// panels!
	$(".panel").hover(function() {
		$(this).find(".panel-content .icon").stop().animate({ height: "55px", marginTop: "10px"  }, 200 );
		$(this).find(".panel-content .submit").stop().animate({ left: "175px"  }, 500 );
		$(this).find(".panel-content a").css("color", "#454545");
	} , function() { 
		$(this).find(".panel-content .icon").stop().animate({ height: "64px", marginTop: "0px" }, 200 );
		$(this).find(".panel-content .submit").stop().animate({ left: "100px"  }, 1000 );
		$(this).find(".panel-content a").css("color", "#669900");
	});			

	// webhostingdomeincheckfocus
	$(".panel input[name=domein]").focus(function() {
		$(this).css("color", "#669900");
		if ($(this).val() == "uwnaam.nl") {
			$(this).val("");
		}
	});
	$(".panel input[name=domein]").blur(function() {
		$(this).css("color", "#666666");
		if ($(this).val() == "") {
			$(this).val("uwnaam.nl");
		}
	});

	
	
	// Portfolio categorie menu
	$(".categorieen ul li").hover(function() {
		$(this).find("a").stop().animate({ paddingLeft: "5px" }, 200 );
	} , function() { 
		$(this).find("a").stop().animate({ paddingLeft: "0px" }, 200 );
	});				

	// the panorama 
	$("#pan1").mouseover(function () {
			$("#panorama img").stop().animate({ marginLeft: "0px" }, 1500 );
			$("#beams img").stop().animate({ marginLeft: "0px" }, 1400 );
			$("#perspective img").stop().animate({ marginLeft: "0px" }, 1500 );
	});
	$("#pan2").mouseover(function () {
			$("#panorama img").stop().animate({ marginLeft: "-960px" }, 1500 );
			$("#beams img").stop().animate({ marginLeft: "-960px" }, 1400 );
			$("#perspective img").stop().animate({ marginLeft: "-480px" }, 1500 );
	});						
	$("#pan3").mouseover(function () {
			$("#panorama img").stop().animate({ marginLeft: "-1920px" }, 1500 );
			$("#beams img").stop().animate({ marginLeft: "-1920px" }, 1400 );
			$("#perspective img").stop().animate({ marginLeft: "-960px" }, 1500 );
	});	
	$("#pan4").mouseover(function () {
			$("#panorama img").stop().animate({ marginLeft: "-2880px" }, 1500 );
			$("#beams img").stop().animate({ marginLeft: "-2880px" }, 1400 );
			$("#perspective img").stop().animate({ marginLeft: "-1440px" }, 1500 );
	});	
	$("#pan5").mouseover(function () {
			$("#panorama img").stop().animate({ marginLeft: "-3840px" }, 1500 );
			$("#beams img").stop().animate({ marginLeft: "-3840px" }, 1400 );
			$("#perspective img").stop().animate({ marginLeft: "-1920px" }, 1500 );
	});	
	$("#pan6").mouseover(function () {
			$("#panorama img").stop().animate({ marginLeft: "-4800px" }, 1500 );
			$("#beams img").stop().animate({ marginLeft: "-4800px" }, 1400 );
			$("#perspective img").stop().animate({ marginLeft: "-2400px" }, 1500 );
	});		
	$("#pan7").mouseover(function () {
			$("#panorama img").stop().animate({ marginLeft: "-5760px" }, 1500 );
			$("#beams img").stop().animate({ marginLeft: "-5760px" }, 1400 );
			$("#perspective img").stop().animate({ marginLeft: "-2880px" }, 1500 );
	});		
	
	//voorpagina werk 
	//$(".fp-slide img").css({ opacity: "0.5"  });	
	$(".fp-slide").hover(function() {
		$(this).find(".fp-view").stop().animate({ bottom: "0px"  }, 500 );
	} , function() { 
		$(this).find(".fp-view").stop().delay(200).animate({ bottom: "-50px"  }, 500 );
	});
	
	//ajaxform
	
	$('#contactform').ajaxForm(function(data) {
		if (data==1){
			$('#success').fadeIn(500);
			$('#bademail').fadeOut(500);
			$('#badserver').fadeOut(500);
			$('#contactform').resetForm();
		}
		else if (data==2){
			$('#badserver').fadeIn(500);
		}
		else if (data==3)
		{
			$('#bademail').fadeIn(500);
		}
	});			
	
	//showforms webhosting
	$(".showforms").click(function() {
               $(".forms").slideToggle();
    });	
	
	$('.fp-slide-items').cycle({
   	fx:     'scrollHorz', //blindX
   	speed: '700',
   	timeout: '4000',
   	random: 1
   });		
});		
