/* HINTS PLUGIN */
/**
* @author Remy Sharp
* @url http://remysharp.com/2007/01/25/jquery-tutorial-text-box-hints/
*/

(function ($) {

$.fn.hint = function (blurClass) {
    if (!blurClass) blurClass = 'blur';
    
    return this.each(function () {
        var $input = $(this),
            title = $input.attr('title'),
            $form = $(this.form),
            $win = $(window);

        function remove() {
            if (this.value === title && $input.hasClass(blurClass)) {
                $input.val('').removeClass(blurClass);
            }
        }

        // only apply logic if the element has the attribute
        if (title) { 
            // on blur, set value to title attr if text is blank
            $input.blur(function () {
                if (this.value === '') {
                    $input.val(title).addClass(blurClass);
                }
            }).focus(remove).blur(); // now change all inputs to title
            
            // clear the pre-defined text when form is submitted
            $form.submit(remove);
            $win.unload(remove); // handles Firefox's autocomplete
        }
    });
};

})(jQuery);
/* END HINTS */

Shadowbox.loadSkin('skin', 'public/javascripts/shadowbox');

$(document).ready(function() { 
	
	Shadowbox.init({
		skipSetup: true,
		overlayColor: '#fff',
		animSequence: 'sync'
	});
	
	// Removable value text on inputs
	$('input[type=text]').hint();
	
	// End
	
	$('#useful_info a, #wwd_links a, .sitemap_what_we_do a').click(function() {
		
		$('#shadowbox_body').removeClass('case_study').addClass('useful_info');
		
		Shadowbox.open({
			player:     'iframe',
		    content:    $(this).attr('href')+'/ajax',
			height:     $(this).attr('class'),
		    width:      530,
			title: 		'&nbsp;'
		});

		return false;		
	});
	
	// Homepage slider
	$('#homepage_slider .button').click(function() {
		
		var parentId = $(this).parent().attr('id');
		var parentId = '#'+parentId;
		
		if($(parentId).hasClass('selectedPanel')) {
			location.href = $(this).attr('href'); 
			return false;
		}
		
		$('.view_button').removeClass('view_button').html('Read more');
		
		$('#homepage_slider li').each(function() {
			if('#'+$(this).attr('id') != parentId) 
			{ 
				$('#'+$(this).attr('id')+' .content').slideUp(); 
			}
		});
		
		$('#homepage_slider .button').animate({top : '-6px'});
		
		if(!$('.selectedPanel').hasClass('selectedPanel')) 
		{ 
			if(parentId == '#how_we_do_it_slider') { $('#how_we_do_it_slider .top_section').animate({height: '65px'}); }
			$(parentId+' .extra_info').slideDown();
		}
		else
		{
			if(parentId == '#how_we_do_it_slider') { $('#how_we_do_it_slider .top_section').css({height: 'auto'}); }
			$(parentId+' .extra_info').show();
			$(parentId+' .content').slideDown();
		}
		
		$('#homepage_slider li').animate({paddingBottom: '0'}); 
			
		$('.selectedPanel').removeClass('selectedPanel');
		
		$(parentId).addClass('selectedPanel');

		$(parentId+' .button').addClass('view_button').html('View page');
				
		return false;		
	}); 
	
	// Case study links
	$('.case_study_links a, .sitemap_case_studies a').click(function() {
		
		$('#shadowbox_body').removeClass('useful_info').addClass('case_study');
		
		Shadowbox.open({
			player:     'iframe',
		    content:    $(this).attr('href')+'/ajax',
		    height:     $(this).attr('class'),
		    width:      530,
			title: 		'&nbsp;'
		});
		
		return false;		
	});
	
	// Open in new window
	$('.newWindow').click(function() { 
		window.open(this.href, 'new_window');
		return false;
	});
	
	// What we do IE6 Fix
	if($.browser.msie && ($.browser.version == 6.0)) {
		$('#wwd_links a').hover(
			function () { $(this).children('.button').css({backgroundPosition: 'bottom left'}); },
			function () { $(this).children('.button').css({backgroundPosition: 'top left'}); }
		);
	}
	
	// Fix PNGs in IE 6
	if($.browser.msie && ($.browser.version == 6.0)) {
		$.ifixpng(base_url+'public/images/pixel.gif');
		$('#specialist_team a').ifixpng(); 
	}
		
});