$(document).ready(function()
{
	var shadowbox_options = ''; //';options={animate:false}';
	
	$('label').each(function()
	{
		if(!$(this).parent().parent().hasClass('inputgroup'))
		{
			$(this).addClass('overlabel');
		}
		
		$('label.overlabel').overlabel();
	});
	
	$('select option:first-child').each(function()
	{
		var parent_id = $(this).parent().attr('id');
		
		var label_text = $('label[for="'+parent_id+'"]').html();
		
		$(this).html(label_text);
		
		$('label[for="'+parent_id+'"]').removeClass('overlabel-apply').hide(); //css('width','100px');
	});
	
	// What we do web text and view all replacement
	$('ul#nav li.subnav:eq(0) ul li:eq(0) a:eq(0)').append('<span>Looking for an online presence which will totally blow you away?</span>');
	$('ul#nav li.subnav:eq(0) ul li:eq(0) ul li:last a').html('<em>Would you like to see our full list<br >of Web Services?</em>');
	// What we do print text and view all replacement
	$('ul#nav li.subnav:eq(0) ul li:eq(7) a:eq(0)').append('<span>Want an agency that really can deliver exceptional graphic design &amp; print?</span>');
	$('ul#nav li.subnav:eq(0) ul li:eq(7) ul li:last a').html('<em>Would you like to see our full list<br >of Print Services?</em>');
	// What we do creative text and view all replacement
	$('ul#nav li.subnav:eq(0) ul li:eq(14) a:eq(0)').append('<span>So we have the knowledge, the ability, but do we have the creativity? Of course.</span>');
	$('ul#nav li.subnav:eq(0) ul li:eq(14) ul li:last a').html('<em>Would you like to see our full list<br >of Creative Services?</em>');
	// What we do digital text and view all replacement
	$('ul#nav li.subnav:eq(0) ul li:eq(21) a:eq(0)').append('<span>Make your website a success with a complete digital marketing strategy from Dusza.</span>');
	$('ul#nav li.subnav:eq(0) ul li:eq(21) ul li:last a').html('<em>Would you like to see our full list<br >of Digital Media Services?</em>');
	// Hide consultancy from what we do nav
	$('ul#nav li.subnav:eq(0) ul li:eq(28)').css('display','none');
	
	// Remove last two showcase sub nav links
	$('ul#nav li.subnav:eq(1) ul li:eq(4)').css('display','none');
	$('ul#nav li.subnav:eq(1) ul li:eq(5)').css('display','none');
	// Rawk extra text
	$('ul#nav li.subnav:eq(1) ul li:eq(0) a:eq(0)').append('<span>A successful eCommerce choose Dusza for branding, eCommerce and digital marketing</span>');
	// Paramount extra text
	$('ul#nav li.subnav:eq(1) ul li:eq(1) a:eq(0)').append('<span>health &amp; safety specialists choose Dusza for a ground breaking CRM system</span>');
	// BGN extra text
	$('ul#nav li.subnav:eq(1) ul li:eq(2) a:eq(0)').append('<span>A catholic school choose Dusza for web design and content management</span>');
	// G&H extra text
	$('ul#nav li.subnav:eq(1) ul li:eq(3) a:eq(0)').append('<span>A construction company choose Dusza for re-branding content managed web site</span>');
	// Show quote to the right
	if(!$.browser.msie)
	{
		$('ul#nav li.subnav:eq(1) ul li:eq(0)').before('<li class="quote">we are really proud of the work we do. In our showcase section you\'ll be able to see the wide range of services we provide to our clients on a daily basis!<br /><br /><em><a href="http://www.dusza.co.uk/4/showcase/" title="showcase">would you like to see everything in our showcase?</a></li>');
	}
	
	// Portfolio web text and view all replacement
	$('ul#nav li.subnav:eq(2) ul li:eq(0) a:eq(0)').append('<span>Why not have a look at the selection of web work we have already had the pleasure of creating?</span>');
	$('ul#nav li.subnav:eq(2) ul li:eq(0) ul li:last a').html('<em>Would you like to see everything in<br >our Web Portfolio?</em>');
	// Portfolio print text and view all replacement
	$('ul#nav li.subnav:eq(2) ul li:eq(7) a:eq(0)').append('<span>or you may like to view our print portfolio<br />covering everything from graphic design, brochures and flyers!</span>');
	$('ul#nav li.subnav:eq(2) ul li:eq(7) ul li:last a').html('<em>Would you like to see everything in<br >our Print Portfolio?</em>');
	// Portfolio creative text and view all replacement
	$('ul#nav li.subnav:eq(2) ul li:eq(14) a:eq(0)').append('<span>we love branding, it\'s another passion of ours<br />and here you can view a selection of our favourite brand work.</span>');
	$('ul#nav li.subnav:eq(2) ul li:eq(14) ul li:last a').html('<em>Would you like to see everything in<br >our Creative Services?</em>');
	
	// Who we are what we think text and view all replacement
	$('ul#nav li.subnav:eq(3) ul li:eq(0) a:eq(0)').append('<span>read about our vision and mission statement.</span>');
	// Who we are what our clients think text and view all replacement
	$('ul#nav li.subnav:eq(3) ul li:eq(3) a:eq(0)').append('<span>find out exactly what our clients think of working with dusza</span>');
	
	if($('input#mailing_list_email_address').length > 0)
	{
		$('input#mailing_list_email_address').focus(function()
		{
			if($(this).val() == 'Email Address')
			{
				$(this).val('');
			}
		});
		
		$('input#mailing_list_email_address').blur(function()
		{
			if($(this).val() == '')
			{
				$(this).val('Email Address');
			}
		});
	}
	
	if($("ul#subnav").length > 0)
	{
		if(!$.browser.msie || $.browser.version != 5.5)
		{
			$("ul#subnav").css("display","none");
		}
	}
	
	$(function()
	{  
		if ($.browser.msie && parseInt($.browser.version)< 7)
		{
			$("ul#nav li.subnav").hover(function()
			{  
				$(this).addClass("active");  
            },
			function()
			{
				$(this).removeClass("active");  
            });
			
			$("ul#nav li.subnav ul li.subsubnav").hover(function()
			{  
				$(this).addClass("active");  
            },
			function()
			{
				$(this).removeClass("active");  
            });
		}
	});
	
	$('a[rel*="external"]').click(function()
	{
		open($(this).attr('href'));
		return false;
	});
	
	$('a[rel*="shadowbox"]').each(function()
	{
		if(!$(this).hasClass('page_video'))
		{
			var enlarge_img = $(this).attr('rel').split(' ');
			
			if(enlarge_img != 'undefined' && enlarge_img != '')
			{
				$(this).removeAttr('rel');
				
				if(enlarge_img[1] != 'undefined')
				{
					$(this).attr('rel', enlarge_img[1]+shadowbox_options);
				}
				else
				{
					$(this).attr('rel', enlarge_img[0]+shadowbox_options);
				}
			}
		}
	});
	
	var nav_timeout = 'undefined';
	
	$("li.subnav").bind("mouseenter",function()
	{
		if(nav_timeout != 'undefined')
		{
			clearTimeout(nav_timeout);
		}
		
		$("li.subnav.active").removeClass("active");
		$(this).addClass("active");
	}).bind("mouseleave",function()
	{
		nav_timeout = setTimeout(function()
		{
			$("li.subnav.active").removeClass("active");
		},2000);
	});
	
	$("ul.thumbs li a img").each(function()
	{
		$.preloadImages.add($(this).attr("src").replace("thumb", "mid"));
	});
	
	$("ul.thumbs li a").mouseover(function()
	{
		$("img#full").attr("src", ($(this).attr('href')).replace("full", "mid"));
		$("img#full").attr("alt", ($(this).attr('alt')));
		$("a#enlarge").attr("href", ($(this).attr('href')).replace("thumb", "full"));
		$("a#enlarge").attr("title", ($(this).attr('title')));
	});
	
	$("ul.thumbs li:first a").click(function()
	{
		$("a#enlarge").click();
	});
	
	$("ul.thumbs li a").click(function()
	{
		$("img#full").attr("src", ($(this).attr('href')).replace("full", "mid"));
		$("img#full").attr("alt", ($(this).attr('alt')));
		$("a#enlarge").attr("href", ($(this).attr('href')).replace("thumb", "full"));
		$("a#enlarge").attr("title", ($(this).attr('title')));
		return false;
	});
	
	if($("li.help a").length > 0)
	{
		$("li.help a").click(function()
		{
			return false;
		});
		
		var help_timeout = 'undefined';
		
		$("li.help a").bind("mouseenter",function()
		{
			if(help_timeout != 'undefined')
			{
				clearTimeout(help_timeout);
			}
			$("li.help div").fadeOut();
			$(this).next().addClass('active').fadeIn();
		}).bind("mouseleave",function()
		{
			help_timeout = setTimeout(function()
			{
				$('li.help div.active').removeClass('active').fadeOut();
			},2000);
		});
		
		$('input').focus(function()
		{
			$('li.help div.active').removeClass('active').fadeOut();
		});
		
		$('select').focus(function()
		{
			$('li.help div.active').removeClass('active').fadeOut();
		});
		
		$('textarea').focus(function()
		{
			$('li.help div.active').removeClass('active').fadeOut();
		});
	}
});

jQuery.fn.overlabel = function() {
    this.each(function(index) {
        var label = $(this); var field;
        var id = this.htmlFor || label.attr('for');
        if (id && (field = document.getElementById(id))) {
            var control = $(field);
            label.addClass("overlabel-apply");
            if (field.value !== '') {
                label.css("text-indent", "-1000px");
            }
            control.focus(function () {label.css("text-indent", "-1000px");}).blur(function () {
                if (this.value === '') {
                    label.css("text-indent", "0px");
                }
            });
            label.click(function() {
                var label = $(this); var field;
                var id = this.htmlFor || label.attr('for');
                if (id && (field = document.getElementById(id))) {
                    field.focus();
                }
            });
        }
    });
};