
	// Style the headings
$(function(){
	Cufon('h1, h2');
});
	//$("a[rel=gallery]").fancybox({
	//	'autoScale':'false',
	//	'onStart': pauseCycle,
	//	'onClosed': resumeCycle,
	//	'titlePosition' : 'over',
	//	'titleFormat' : function(title, currentArray, currentIndex, currentOpts) {
	//		return '<span id="fancybox-title-over">Afbeelding ' + (currentIndex + 1) + ' van ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
	//	}		
	//});
                    
	// PORTFOLIO
	$('#portfoliobox_content').cycle({ speed: 2000, timeout: 2000 });
					
	function pauseCycle(){ $('#portfoliobox_content').cycle('pause'); }
	function resumeCycle(){ $('#portfoliobox_content').cycle('resume'); }

// EMAIL FIX
$("a.email").live('click', function() { $(this).attr('href', 'mailto:info@elseonline.nl'); });

// FORM SUBMIT FUNCTION
$(function(){
	$('.submit2').live('click', function(e) {
	
		// VARS
		var formParams = "email=jelle@else";
		var dataString = $(this).parents('form:first').serialize();
		//var href_url = $(this).parents('form:first').attr('action');
		var href_url = "/index.php?page=contact";
		alert(dataString);
		// TARGETS
		var target = "#right_content";
		var content_target = "#right_content > .inner_content";
	
		$.ajax({
			type: 'POST',
			url: href_url,
			async: false,
			data: formParams,
			success: function( data ) {
				var content = $( data ).find(target);
				$(target).append( content );
			}
		});
	return false;
	});
});

// CONTENTLINKS
$('a.contentmain').live('click', function(e) {

	var href_url = $(this).attr('href').replace("http://www.elseonline.nl", "");
	//alert(href_url);
	
	$('#menu').find('a').each( function(){
		if( $(this).attr('href') == href_url){
			$(this).click();
		}
	});
	
	return false;
});
	
	
// PANEL CHANGE FUNCTION
$(function(){

	$('a.sub, a.main').live('click', function(e) {
    	
		// CHECK IF LINK IS NOT ACTIVE AND PREVENT DOUBLE LOADING
		if(! $(this).hasClass('active') && $(this).find('.loading_img').length == 0){
			
			// VARS
			var href_url = $(this).attr('href');
			var clicked = $(this);
			var clicked_ul = $(this).parent().parent();
				
			// TARGETS
			if($(this).hasClass('main')){ 
				var target = "#content";
				var content_target = "#content";
			}else{
				var target = "#right_content";
				var content_target = "#right_content > .inner_content";
			}

			// LOAD CONTENT
			$.ajax({
				url: href_url,
				contentType : "application/x-www-form-urlencoded; charset=iso-8859-1",
				beforeSend: function(){ 

					// SHOW LOADING IMAGE
					$(clicked).append('<img src="/images/loading.gif" class="loading_img">');
					$(clicked_ul).find('img').fadeIn();
				},
				success: function(data){
						
					// GET CONTENT
					var content = $(data).find(target);
							
					// SET WRAPPERS
					var target_width = $(target).width();
					$(target).wrapInner('<div style="width: ' + target_width + 'px;" />');
							
					// HIDE PANEL
					$(target).animate({width: 'hide'}, 500, function() { 
						$(target).html(content);	// PLACE CONTENT
						showContent();				// SHOW CONTENT
					});
				}
			});
			
			// SHOW CONTENT
			function showContent(){

				// REMOVE LOADING IMAGE
				$(clicked_ul).find('img').fadeOut(500, function () { $(clicked_ul).find('img').remove(); });
				
				// REMOVE CLASS
				$(clicked_ul).find('li').each(function(){
					$(this).find('a').removeClass('active');
				});

				// SET CLASS
				$(clicked).addClass('active');
					
				$(target).animate({width: 'show'}, 500);

				// PORTFOLIO
				$('#portfoliobox_content').cycle({ speed: 2000, timeout: 2000 });
				
				// REMOVE WRAPPER DIV
				//$(target).find('div').contents().unwrap();
			}	
			
		}
			
		// CLOSE
		return false; 
	});
});


