
$(function(){
	
	if ($.browser.msie && $.browser.version < 7)
		$('img[src$=.png]').pngfix();

	$('img[hover],input[hover]').imghover();
		
	$('input[type=text], textarea').focus(function () {
         $(this).addClass('active');
    }).blur(function () {
		$(this).removeClass('active');
	});
	
	var GoogleMapsLoaded = false;
	
	// show/hide contact-pane
	$("a#contactbttn, a#closebttn").click(function () {
        if ($("div#contactCon").is(":hidden")) {
			$("div#serviceNav").addClass('active');
            $("div#contactCon").slideDown("slow");
            
            setTimeout(function() {
	            if (GBrowserIsCompatible() && !GoogleMapsLoaded) {
	                map = new GMap2(document.getElementById('googleMapsCon'));
	                map.setCenter(new GLatLng(51.9184395, 4.5232784), 13);
	
	                point   = new GLatLng(51.9184395, 4.5232784);
	                marker  = new GMarker(point);
	                
	                map.addOverlay(marker);
	                
	                map.addControl(new GSmallMapControl());
	                map.addControl(new GMapTypeControl());
	                
	                GoogleMapsLoaded = true;
	            }
	        }, 1000);
            
		    return false;
        } else {
            $("div#contactCon").slideUp("slow", function (){
				$("div#serviceNav").removeClass('active');
			});			
		    return false;
        }
    });
	
	// cycle logos in header
	$('#logos').cycle({ 
	    fx: 'scrollDown' 
	});
	
	// activate paging for calendar-block
	if ( $('ul#calendar').length > 0 ) {
		$('ul#calendar').paging({
			itemsPerPage: 4,
			elementType: 'li',
			prevText: '&lt;',
			nextText: '&gt;',
			selectedClass: 'selected',
			navClass: 'customnav',
			addNav: 'before',
			showPageNumbers: 'false'
		}).bind('pagingBeforePageChange',function(){
			//console.log('before');
		}).bind('pagingAfterPageChange',function(){
			//console.log('after');
		});
	};
	
	// toggle panels (alumni - FAQ)
	$('.panel').hide();
	$('.wrapper ul li a.details').click(function() {
		var id = $(this).parents('div.wrapper ul').attr('rel');
		$('#panel' + id).slideToggle(200, function(){ $(this).parent().toggleClass('highlight') });
		return false;
	});
	$('.wrapper ul').click(function() {
		var id = $(this).attr('rel');
		$('#panel' + id).slideToggle(200, function(){ $(this).parent().toggleClass('highlight') });
		return false;
	});
	
	// activate paging for career companies
	if ( $('.companylistTab').length > 0 ) {
		$('.companylistTab').paging({
			itemsPerPage: 4,
			elementType: 'tr',
			prevText: '&lt;',
			nextText: '&gt;',
			selectedClass: 'selected',
			navClass: 'customnav',
			addNav: 'after',
			showPageNumbers: 'false'
		});
	};
	
	// activate paging for webshop
	if ( $('.shoplistTab').length > 0 ) {
		$('.shoplistTab').paging({
			itemsPerPage: 9,
			elementType: 'tr',
			prevText: '&lt;',
			nextText: '&gt;',
			selectedClass: 'selected',
			navClass: 'customnav',
			addNav: 'after',
			showPageNumbers: 'false'
		});
	};
	
    
    $("a[rel=track]").click(function(e) {
        url = $(this).attr("href");
        pageTracker._trackPageview("outgoing:" + url);
    });
	
	$("a[rel=addcart]").click(function(e) {
	    e.preventDefault();
	    e.stopPropagation();
	    var link = $(this);
	    var url  = link.attr("href") + "/ajax/1";
	    var id   = link.attr("id").replace("link-product-", "");
	    
	    link.css("background-image", "url(/images/ajax-loader.gif)");
	    
	    $("div#shoppingcart-wrapper").load(
	        url, 
	        null, 
	        function(responseText, textStatus, XMLHttpRequest) {
	            link.css("background-image", "url(/images/icons/shoppingcarts.gif)");
	            
	            if (document.getElementById("shoppingcart-product-" + id)) {
	                effectTarget = "#shoppingcart-product-" + id;
	            } else {
	                effectTarget = "#shoppingcart-wrapper"; 
	            }
	            
	            $("#list-product-" + id).effect("transfer", {
	                to : effectTarget, 
	                className: "ui-effects-transfer"}, 
	                500
	            ); 
	        }
	    );
	    return false;
	});
    

	// Fix tables
	var tr = $('div.companylist table tr:last');
	var tdCount = tr.find('td').length;
	for (var i=0; i<(3-tdCount); i++) {
		$('<td></td>').css('border',0).appendTo(tr);
	}
	
	
	// toggle loginform on shoppages
	$("a#toggleloginform").click(function () {
        if ($("div#shoploginform").is(":hidden")) {
            $("div#shoploginform").slideDown("slow");            
		    return false;
        } else {
            $("div#shoploginform").slideUp("slow", function (){
				// nothing to do
			});			
		    return false;
        }
    });
	
	
	$('input[type="text"]').addClass("text");

});


$(window).load(function(){
	if ($.browser.msie && $.browser.version <= 8) {
		$('table.companylistTab img').each(function(){
			var h = this.height;
			$(this).parent().css('lineHeight','1em'); // reset for IE8
			$(this).css('marginTop',parseInt((134-h)/2)+'px');
		});
	}
});

;(function($){

	$.fn.pngfix = function () {	
		if ($.browser.msie && $.browser.version < 7) {
			return this.each (function () {
				$(this).css({
					filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+this.src+"')"
				});
				this.src = 'images/blank.gif';
			});
		} else {
			return this;
		}
	};

	$.prefetch = function() {
		for(var i = 0; i<arguments.length; i++)  {
			$("<img>").attr("src", arguments[i]);
		}
	}

	$.fn.imghover = function () {
		return this.each (function () {
			$(this).data('__img__original', this.src);
			$.prefetch($(this).attr('hover'));
		}).hover(function(){
			this.src = $(this).attr('hover');
		},function(){
			this.src = $(this).data('__img__original');
		});
	};
	
})(jQuery);


function trackFlashLink(url) {
    try {
        pageTracker._trackPageview("outgoing:" + url);
    } catch(e) {}
}

function updateAccountDetails() {
    $("div#accountdetailwrapper").load("/account/view");
    $("div#accountdetailwrapper").effect("highlight", {}, 3000);
}