$(document).ready(function() {
	
	$('a').each(function(){
		if($(this).attr('href') !== undefined)
		{
			if($(this).attr('href').substr(0,4) == 'http' && $(this).attr('href').substr(0, 22) != 'http://www.youtube.com')
			{
				$(this).attr('target','_blank');
			}
		}
	});
	
	$('.controls a').click(function(){
		$('.controls a').removeClass('selected');
		$(this).addClass(' selected');
		return false;
	});
	$("a.item").click(function(){
		$('div.item2').hide();
		$('div.item3').hide();
		$('div.item4').hide();
		$('div.item5').hide();
		$('div.item6').hide();										
		$('div.item7').hide();										
		$('div.item').fadeIn('fast');
	});
	$("a.item2").click(function(){
		$('div.item').hide();
		$('div.item3').hide();
		$('div.item4').hide();
		$('div.item5').hide();
		$('div.item6').hide();										
		$('div.item7').hide();										
		$('div.item2').fadeIn('fast');
	});
	$("a.item3").click(function(){
		$('div.item').hide();
		$('div.item2').hide();
		$('div.item4').hide();
		$('div.item5').hide();
		$('div.item6').hide();										
		$('div.item7').hide();										
		$('div.item3').fadeIn('fast');
	});
	$("a.item4").click(function(){
		$('div.item').hide();
		$('div.item2').hide();
		$('div.item3').hide();
		$('div.item5').hide();
		$('div.item6').hide();										
		$('div.item7').hide();										
		$('div.item4').fadeIn('fast');
	});	
	$("a.item5").click(function(){
		$('div.item').hide();
		$('div.item2').hide();
		$('div.item3').hide();
		$('div.item4').hide();
		$('div.item6').hide();										
		$('div.item7').hide();										
		$('div.item5').fadeIn('fast');
	});
	$("a.item6").click(function(){
		$('div.item').hide();
		$('div.item2').hide();
		$('div.item3').hide();
		$('div.item4').hide();
		$('div.item5').hide();										
		$('div.item7').hide();										
		$('div.item6').fadeIn('fast');
	});
	$("a.item7").click(function(){
		$('div.item').hide();
		$('div.item2').hide();
		$('div.item3').hide();
		$('div.item4').hide();
		$('div.item5').hide();
		$('div.item6').hide();										
		$('div.item7').fadeIn('fast');
	});
    $(function() {
		$(".partners .right li a").click(function(){
			$.getJSON("/partners/?ajax&id=" + $(this).parent().attr("class").split("-")[1], function(data)
			{
				$('.overlay .image a').attr('href', data.url);
				$('.overlay .image img').attr('src', '/dyn/partners/' + data.image).attr('alt', data.name);
				$('.overlay h3 a').attr('href', data.url);
				$('.overlay h3 a').html('Visit the ' + data.name + ' website');
				$('.overlay .b p').html(data.description);
				
			});
			$(this).colorbox({
				width:"688px",
				inline:true,
				href:".overlay"
			});
		});
		$(".support .link7").colorbox({
			width:"688px",
			inline:true,
			href:".overlay"}
		);		
    });
	$(".ank").anchor();
	
	$(".scrollable").scrollable({
		size: 1,
		clickable: false
	}).navigator();	

	$('#list1b').accordion({
		autoheight: false
	});
	
	var accordions = jQuery('#list1b');
	jQuery('#switch select').change(function() {
		accordions.accordion("activate", this.selectedIndex-1 );
	});
	
	jQuery('#close').click(function() {
		accordions.accordion("activate", -1);
	});
	
	jQuery('#switch2').change(function() {
		accordions.accordion("activate", this.value);
	});
	
	jQuery('#enable').click(function() {
		accordions.accordion("enable");
	});
	
	jQuery('#disable').click(function() {
		accordions.accordion("disable");
	});
	
	jQuery('#remove').click(function() {
		accordions.accordion("destroy");
		wizardButtons.unbind("click");
	});

	$('.draw h3').click(function(){
		$('.draw h3').removeClass(' active');
		$(this).addClass(' active');
		return false;
	});
	$(".draw1").click(function(){
		$('.the-project1').slideDown("fast");
		$('.the-project2').slideUp("fast");
		$('.the-project3').slideUp("fast");
		$('.the-project4').slideUp("fast");
		$('.the-project5').slideUp("fast");
		$('.the-project6').slideUp("fast");
	});
	$(".draw2").click(function(){
		$('.the-project1').slideUp("fast");
		$('.the-project2').slideDown("fast");
		$('.the-project3').slideUp("fast");
		$('.the-project4').slideUp("fast");
		$('.the-project5').slideUp("fast");
		$('.the-project6').slideUp("fast");
	});
	$(".draw3").click(function(){
		$('.the-project1').slideUp("fast");
		$('.the-project2').slideUp("fast");
		$('.the-project3').slideDown("fast");
		$('.the-project4').slideUp("fast");
		$('.the-project5').slideUp("fast");
		$('.the-project6').slideUp("fast");
	});
	$(".draw4").click(function(){
		$('.the-project1').slideUp("fast");
		$('.the-project2').slideUp("fast");
		$('.the-project3').slideUp("fast");
		$('.the-project4').slideDown("fast");
		$('.the-project5').slideUp("fast");
		$('.the-project6').slideUp("fast");
	});	
	$(".draw5").click(function(){
		$('.the-project1').slideUp("fast");
		$('.the-project2').slideUp("fast");
		$('.the-project3').slideUp("fast");
		$('.the-project4').slideUp("fast");
		$('.the-project5').slideDown("fast");
		$('.the-project6').slideUp("fast");
	});	
	$(".draw6").click(function(){
		$('.the-project1').slideUp("fast");
		$('.the-project2').slideUp("fast");
		$('.the-project3').slideUp("fast");
		$('.the-project4').slideUp("fast");
		$('.the-project5').slideUp("fast");
		$('.the-project6').slideDown("fast");
	});	
	
});

jQuery.fn.anchor = function(settings) {
 	settings = jQuery.extend({
		speed : 1100
	}, settings);	
	return this.each(function(){
		var caller = this
		$(caller).click(function (event) {	
			event.preventDefault()
			var locationHref = window.location.href
			var elementClick = $(caller).attr("href")
			var destination = $(elementClick).offset().top;
			$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination}, settings.speed, function() {
				window.location.hash = elementClick
			});
		  	return false;
		})
	})
}

function ValidateTicket(form)
{
	var errors = new Array();
	
	if($('#subject').val().length < 2) errors.push('subject');
	if($('#name').val().length < 2) errors.push('name');
	if($('#customer').val().length < 2) errors.push('customer');
	if($('#tel').val().length < 2) errors.push('tel');
	if($('#email').val().length < 2) errors.push('email');
	if($('#fault').val().length < 2) errors.push('fault');
	
	if(errors.length > 0)
	{
		$.each(errors,function(key){
			$('label[for="'+ errors[key] +'"]').addClass('error');
		});
		alert('Some fields have not been completed successfully.\nThese fields have been marked in red for your attention.');
	}
	else
	{
		return true;
	}
	return false;
}

function ValidateFeedback(form)
{
	var errors = new Array();
	
	if($('#name', form).val().length < 2) errors.push('name');
	if($('#company', form).val().length < 2) errors.push('company');
	if($('#email', form).val().length < 2) errors.push('email');
	if($('#telephone', form).val().length < 2) errors.push('telephone');
	if($('#details', form).val().length < 2) errors.push('details');
	
	if($('#availability', form).val().length < 2) errors.push('availability');
	if($('#productsuit', form).val().length < 2) errors.push('productsuit');
	if($('#reliability', form).val().length < 2) errors.push('reliability');
	if($('#salessupport', form).val().length < 2) errors.push('salessupport');
	if($('#helpdesksupport', form).val().length < 2) errors.push('helpdesksupport');
	if($('#engineerresponse', form).val().length < 2) errors.push('engineerresponse');
	if($('#engineertimekeeping', form).val().length < 2) errors.push('engineertimekeeping');
	if($('#communication', form).val().length < 2) errors.push('communication');
	if($('#service', form).val().length < 2) errors.push('service');
	if($('#experience', form).val().length < 2) errors.push('experience');
	
	if(errors.length > 0)
	{
		$.each(errors,function(key){
			$('label[for="'+ errors[key] +'"]').addClass('error');
		});
		alert('Some fields have not been completed successfully.\nThese fields have been marked in red for your attention.');
	}
	else
	{
		form.submit();
	}
	return false;
}

function ValidateCallback(form)
{
	var errors = new Array();
	
	if($('#time', form).val().length < 2) errors.push('time');
	if($('#telephone', form).val().length < 2) errors.push('telephone');
	if($('#company', form).val().length < 2) errors.push('company');
	if($('#name', form).val().length < 2) errors.push('name');
	
	if(errors.length > 0)
	{
		$.each(errors,function(key){
			$('label[for="'+ errors[key] +'"]').addClass('error');
		});
		alert('Some fields have not been completed successfully.\nThese fields have been marked in red for your attention.');
	}
	else
	{
		form.submit();
	}
	return false;
}

function ValidateContact(form)
{
	var errors = new Array();
	
	if($('#department', form).val().length < 2) errors.push('department');
	if($('#title', form).val().length < 2) errors.push('title');
	if($('#firstname', form).val().length < 2) errors.push('firstname');
	if($('#lastname', form).val().length < 2) errors.push('lastname');
	if($('#email', form).val().length < 2) errors.push('email');
	if($('#preference', form).val().length < 2) errors.push('preference');
	if($('#remarks', form).val().length < 2) errors.push('remarks');
	
	if(errors.length > 0)
	{
		$.each(errors,function(key){
			$('label[for="'+ errors[key] +'"]').addClass('error');
		});
		alert('Some fields have not been completed successfully.\nThese fields have been marked in red for your attention.');
	}
	else
	{
		form.submit();
	}
	return false;
}
			
function UpdatePositions(department)
{
	$('select#position option').remove();
	$('select#position').append('<option value="">Select One</option>');
	
	for(var key in positions[department])
	{
		$('select#position').append('<option value="' + positions[department][key][0] + '">' + positions[department][key][1] + '</option>')
	}
	
	return false;
}

function ValidateInterest(form)
{
	var errors = new Array();
	
	if($('#name', form).val().length < 2) errors.push('name');
	if($('#email', form).val().length < 2) errors.push('email');
	if($('#cv', form).val().length < 2) errors.push('cv');
	
	if(errors.length > 0)
	{
		$.each(errors,function(key){
			$('label[for="'+ errors[key] +'"]').addClass('error');
		});
		alert('Some fields have not been completed successfully.\nThese fields have been marked in red for your attention.');
	}
	else
	{
		form.submit();
	}
	return false;
}

function ValidateInvite(form)
{
	var errors = new Array();
	
	$('label', form).removeClass('error');
	
	if($('#name', form).val().length < 2) errors.push('name');
	if($('#company', form).val().length < 2) errors.push('company');
	if($('#position', form).val().length < 2) errors.push('position');
	if($('#email', form).val().length < 2) errors.push('email');
	if($('#phone', form).val().length < 2) errors.push('phone');
	
	if(errors.length > 0)
	{
		$.each(errors,function(key){
			$('label[for="'+ errors[key] +'"]').addClass('error');
		});
		alert('Some fields have not been completed successfully.\nThese fields have been marked in red for your attention.');
	}
	else
	{
		form.submit();
	}
}
