// JavaScript Document
$(document).ready(function(){
	$('a.port_item').hoverIntent({
		over : function(){
			$(this).next().fadeIn();
		},
		out : function(){/**/},
		interval : 50
	});
	$('.port_item_contents ul li').mouseleave(function(){
		$(this).find('dl.bubble:visible').fadeOut();
	});
	
	$('#port_emarketing div.port_item_contents, #port_print div.port_item_contents, #port_identity div.port_item_contents').hide();
	var $open_h3 = $('#port_list h3:first');
	$('#port_list h3').click(function(){
		var $h3 = $(this);
		if ($h3.parent().attr('id') != $open_h3.parent().attr('id')) {
			$open_h3.next().slideToggle(300);
			$h3.next().slideToggle(300, function(){
				$open_h3 = $h3;
			});
			$h3.addClass('visible');
			$open_h3.removeClass('visible');
		}
	});
	
	$('#item_preview').hoverIntent(function(){
		$('#item_preview img.item_preview_enlarge').fadeIn();
	}, function(){
		$('#item_preview img.item_preview_enlarge').fadeOut();
	});
	
	$('.bubble').click(function(e){
		e.preventDefault();
		window.location = $(this).prev('a.port_item').attr('href');
	});
	
	$('#item_images ul li').each(function(index){
		$(this).find('span.number').text(index + 1);
	});
	$('#item_images ul li span.overlay').css({opacity: 0.5});
	$('#item_images ul li').hoverIntent({
		over: function(){
			var $this = $(this);
			$this.find('span.overlay').animate({opacity: 0}).end()
			.find('span.number').animate({opacity: 0.5});
		},
		out: function(){
			var $this = $(this);
			$this.find('span.overlay').animate({opacity: 0.5}).end()
			.find('span.number').animate({opacity: 1});
		},
		interval: 50
	});
	$('#swap_holder li:not(#img_lg_0)').hide(); // hide the rest of lg images.
	$('#item_images ul li a').click(function(e){e.preventDefault();});
	$('#item_images ul li').click(function(e){
		var $this = $(this);
		var new_img = $this.find('a:first').attr('href');
		var visible_img = $('#swap_holder li:visible').attr('id');
		if ('#'+visible_img != new_img) {
			$('#swap_holder li:visible').fadeOut(function(){
				$(this).hide();
			});
			$('li'+new_img).fadeIn();
			$('#swap_holder .item_preview_enlarge').hide();
		}
	});
	// global
	$.Juitter.start({
		searchType:"fromUser",
		searchObject:"Formcode",
		lang:"en",
		live:"live-60",
		placeHolder:"juitterContainer",
		loadMSG: "Loading latest tweet...",
		total: 1,
		readMore: "Read it on Twitter",
		nameUser:"text",
		openExternalLinks:"newWindow",
		filter:"sex->*BAD word*,porn->*BAD word*,fuck->*BAD word*,shit->*BAD word*"
	});
	$('#top_slider').hide();
	$('#client_login a, #close_top_slider').click(function(e){
		e.preventDefault();
		$('#top_slider').slideToggle();
	});
	//portfolio grid
	$('#port_web .port_item_contents ul li a img').load(function(){
		$(this).hide().fadeIn();
	});
	//contact page
	$('#contact_name, #contact_email, #contact_phone, #contact_message').focus(function(e){
		var $this = $(this);
		if ($this.hasClass('contact_idle')) {
			$this.val('').removeClass('contact_idle');
		}
	});
	$('#contact_name').val('Name').addClass('contact_idle').blur(function(e){
		var $this = $(this);
		if ($this.val() == '') {
			$this.val('Name').addClass('contact_idle');
		}
	});
	$('#contact_email').val('Email').addClass('contact_idle').blur(function(e){
		var $this = $(this);
		if ($this.val() == '') {
			$this.val('Email').addClass('contact_idle');
		}
	});
	$('#contact_phone').val('Phone').addClass('contact_idle').blur(function(e){
		var $this = $(this);
		if ($this.val() == '') {
			$this.val('Phone').addClass('contact_idle');
		}
	});
	$('#contact_message').val('Message').addClass('contact_idle').blur(function(e){
		var $this = $(this);
		if ($this.val() == '') {
			$this.val('Message').addClass('contact_idle');
		}
	});
});
