jQuery.noConflict();
jQuery(function($){
	
	var frontend = 
	{
		init:function()
		{
			this.noImgBorder();
			this.slideShow();
			this.formValidation();
			this.contactForm();
			this.showReel();
		},
		
		noImgBorder:function()
		{
			$('a:has(img)').addClass('noBorder');
		},
		
		slideShow:function()
		{
			if($('#slides').length)
			{
				
				if($('body.PortfolioPage').length) $('div.col-5').eq(0).prepend('<h2 id="imageTitle">'+$('#slides div')[0].title+'</h2>');
				
				$('#slides')
				.before('<ul id="slidesNav">')
				.cycle(
				{
					fx:"scrollLeft",
					pause:1,
					pager:'#slidesNav',
					before:function(){ 
						 if($('#imageTitle').length) $('#imageTitle').text(this.title);
					},
			 		pagerAnchorBuilder: function(idx, slide) 
					{ 
						if(idx < 10) idx = "0"+(idx+1);
    					return '<li><a href="#">'+idx+'</a></li>'; 
					} 
				});
			}
		},
		
		formValidation: function()
		{
			if($('#Form_EnquiryForm').length) $('#Form_EnquiryForm').validate();
			if($('#Form_ContactForm').length) $('#Form_ContactForm').validate();
		},
		
		contactForm:function()
		{
			if($('#contact').length)
			{
				var $contact = $('#contact');
				$contact.hide().insertBefore($('#content'));
				$('#contactTitle').html('<a href="#" id="trigger">Contact us</a>').insertAfter($('#mainNav ul'));
				
				if($('#contact h3').length)
				{
					$contact.show();
					$('#trigger').html('Contact us&nbsp;&nbsp;&nbsp;&nbsp;close x');
				}
				
				$('#trigger').click(function()
				{
					if($(this).text() == 'Contact us')
					{
						$(this).html('Contact us&nbsp;&nbsp;&nbsp;&nbsp;close x');
					}
					else{
						$(this).text('Contact us');
					}
					$contact.slideToggle();
					return false;
				});
			}
		},
		
		showReel:function()
		{
			if($('#reel').length)
			{
				$('#mainNav .container').append($('<a href="#" id="showReel">Showreel</a>'));
			
				$("#reel").dialog({
					autoOpen:false,
					bgiframe: true,
					height: 374,
					width:674,
					modal: true
				});
				
				$('#showReel').click(function(){
					$("#reel").dialog('open');
					$('.ui-widget-overlay').css({opacity:.8});
					return false;
				});
			
				$('.ui-widget-overlay').live("click", function()
				{ 
					$("#reel").dialog('close');
				});
			
			}
		}
	}
	
	frontend.init();

});