if(history.pushState && top.location.href.indexOf('http://') != -1) {
	var is_mobile = navigator.userAgent.match(/(iPhone|iPod|iPad|Android|BlackBerry)/i);
	
	function goTo(url) {
		$('.content-section').html('');
		$('.content-section').addClass('loading');
		
		$('header nav a').removeClass('selected');
		if(is_mobile) {
			$('header nav a').css({background: 'none', color: '#404040'});
		}
		
		var page_href = '';
		$('header nav a').each(
			function() {
				if(this.href == url) {
					page_href = url;
					$(this).addClass('selected');
					if(is_mobile) {
						$(this).css({background: 'rgba(0, 0, 0, 1)', color: '#fff'});
					}
				}
			}
		);
		if(page_href == '') {
			if(url.indexOf('career') != -1) {
				$('header nav a')[3].className = 'selected';
				if(is_mobile) {
					$($('header nav a')[3]).css({background: 'rgba(0, 0, 0, 1)', color: '#fff'});
				}
			}
			else {
				$('header nav a')[0].className = 'selected';
				if(is_mobile) {
					$($('header nav a')[0]).css({background: 'rgba(0, 0, 0, 1)', color: '#fff'});
				}
			}
		}
		
		$.get(
			url,
			function(data) {
				var raw_data = data;
				var data_to_be_inserted = raw_data.split('</header>')[1].split('<footer')[0];
				$('.content-section').remove();
				if(!document.getElementById('content-section-placeholder')) {
					var div = document.createElement('div');
					div.id = 'content-section-placeholder';
					$(div).insertBefore($('footer'));
				}
				$('#content-section-placeholder').hide();
				$('#content-section-placeholder').html(data_to_be_inserted);
				$('#content-section-placeholder').fadeIn();
			}
		);
	}
	
	function openWithAjax() {
		if(this.href != top.location.href) {
			goTo(this.href);
			history.pushState({clicked: true}, this.title, this.href);
		}
		return false;
	}
	
	window.onpopstate = function(e) {
		if(document.getElementById('content-section-placeholder')) {
			goTo(location.href);
		}
	}
	
	$('nav a').click(openWithAjax);
	
	$('a.open-with-ajax').live('click', openWithAjax);
	
	$('#header-logo').click(openWithAjax);
}

/* the facebook like iframe */
$('#facebook-iframe').html('<iframe scrolling="no" frameborder="0" id="facebook-iframe" src="http://www.facebook.com/plugins/like.php?app_id=245816035456971&amp;href=http%3A%2F%2Fro-ro.facebook.com/MBDragan%2F&amp;send=false&amp;layout=standard&amp;width=450&amp;show_faces=false&amp;action=like&amp;colorscheme=light&amp;font&amp;height=35" style="border:none; overflow:hidden; width:450px; height:35px;"></iframe>');

/* the select */
$('.select select').live(
	'change',
	function() {
		this.parentNode.getElementsByTagName('span')[0].innerHTML = this.options[this.selectedIndex].innerHTML;
	}
);

$(document).ready(function() {

		$('.picture_bg li:nth-child(3n)').css('margin', '0px 0px 0px 0px');

		$("a#example1").fancybox();
		
		$("a[rel=example_group]").fancybox({
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'titlePosition' 	: 'over',
				'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
					return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
				}
			});
		$('.name_btn span').corner('round 50px');
		
		
			$('#intern_j').click(function() {
				$('#intern_j').html('<img src="/mbdragan/img/internships_active.png" alt="Internships" />')
				$('#jobs_j').html('<img src="/mbdragan/img/jobs_inactive.png" alt="Internships" />')
				$('#select_job').val('internships')				
			});
			
			$('#jobs_j').click(function() {
				$('#jobs_j').html('<img src="/mbdragan/img/jobs_active.png" alt="Internships" />')
				$('#intern_j').html('<img src="/mbdragan/img/internships_inactive.png" alt="Internships" />')
				$('#select_job').val('jobs')				
			});
			
/* 		$("#title").focus(function() {
		if( this.value == this.defaultValue ) {
			this.value = "";
		}
		}).blur(function() {
			if( !this.value.length ) {
			this.value = this.defaultValue;
			}
		});
		
		$("#description").focus(function() {
		if( this.value == this.defaultValue ) {
			this.value = "";
		}
		}).blur(function() {
			if( !this.value.length ) {
			this.value = this.defaultValue;
			}
		});
			
			
		$("#btn_text").focus(function() {
		if( this.value == this.defaultValue ) {
			this.value = "";
		}
		}).blur(function() {
			if( !this.value.length ) {
			this.value = this.defaultValue;
			}
		}); */
		
		
		$("#username").focus(function() {
		if( this.value == this.defaultValue ) {
			this.value = "";
		}
		}).blur(function() {
			if( !this.value.length ) {
			this.value = this.defaultValue;
			}
		});
		
		$("#password").focus(function() {
		if( this.value == this.defaultValue ) {
			this.value = "";
		}
		}).blur(function() {
			if( !this.value.length ) {
			this.value = this.defaultValue;
			}
		});
			
		
		$('.activate').live('click', function() {
			$('.activate').attr('src', '/mbdragan/img/off.png');
			$(this).attr('src', '/mbdragan/img/on.png');
			id = $(this).attr('id');
			
			$.ajax({
			   type: "POST",
			   url: base_url + "index.php/admin/set_active_fpimage",
			   data: "id="+id
			 });
		});	
		
});

		



