// JavaScript Document
$(document).ready(function(){
	$('ul li:last-child').addClass('lastli');
	$('ul li:first-child').addClass('firstli');
	$('.navbar .firstli a').addClass('addround');
	$('.page-item-34 a').attr('href','http://client.in2one.co.za/accounts/login/?next=/support-requests/').attr('target','_blank');
	$('.googlemap h3').after('<iframe width="425" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.co.za/maps/ms?ie=UTF8&amp;hl=en&amp;msa=0&amp;msid=107845256613854672918.00048831cd8e3f9b46be9&amp;ll=-33.966142,18.837261&amp;spn=0.04983,0.073128&amp;z=13&amp;output=embed"></iframe>');
	
//clients	
$('.rightCol #text-5 .textwidget').hide();
$('.rightCol #text-5 .textwidget').after('<div class="randomclients"></div>');
var clients = $('.rightCol #text-5 .textwidget a')
for(var i=0;i<6;i++){
	var numRand = Math.floor(Math.random()*clients.length);
	$('.randomclients').append(clients[numRand])
	}



	
/*rss*/
$('.rightCol .widget_rss .rssSummary').each(function(){
	var newteks = " ";
	var text = $(this).text();
	var exploded = text.split(' ');	
	for(var i = 0; i < 10; i++){		
		newteks += exploded[i] + ' ';
		}		
	$(this).text(newteks);		
})

/*sitemap anchor*/
$('.sitemap').prepend('<a name="sitemap" id="sitemap"></a>');
	
/*search*/	
$('.screen-reader-text').remove()
$('input#s').attr('title','Search...');
	
	
	
$(':input[title]').each(function() {
  var $this = $(this);
  if($this.val() === '') {
    $this.val($this.attr('title'));
  }
  $this.focus(function() {
    if($this.val() === $this.attr('title')) {
      $this.val('');
    }
  });
  $this.blur(function() {
    if($this.val() === '') {
      $this.val($this.attr('title'));
    }
  });
});	
	
	
	
	
	
	
	$('.searchbut button').toggle(
				function(){
					$('.search').animate({top:-50}, 1000, 'easeOutElastic');				  
			}, function(){
					$('.search').animate({top:-174}, 1000, 'easeOutElastic');
				});

	$('.tab').hover(function(e){
			if(!$(this).hasClass('active'))	{
				$(this).hoverFlow(e.type,{top:0},'fast')
				}	
			}, function(e){
			if(!$(this).hasClass('active'))	{	
				$(this).hoverFlow(e.type,{top:5},'fast')	
			}
			})
	
var slideheight = 0;	
	$('.carousel .carouselhead').toggle(
				function(){
					var slideheight = $(this).parents('.carousel').find('.slideheight').height();							
					if($(this).parents('.carousel').hasClass('active')){
							$(this).parents('.carousel').find('.slide').animate({height:0}, 500);
							$(this).removeClass('carouselheadminus').addClass('carouselheadplus');
						}
					else{					
						$(this).parents('.carousel').find('.slide').animate({height:slideheight}, 500);
						$(this).removeClass('carouselheadplus').addClass('carouselheadminus');
					}
			}, function(){
					var slideheight = $(this).parents('.carousel').find('.slideheight').height();
					if($(this).parents('.carousel').hasClass('active')){
							$(this).parents('.carousel').find('.slide').animate({height:slideheight}, 500);
							$(this).removeClass('carouselheadplus').addClass('carouselheadminus');
						}
					else{					
							$(this).parents('.carousel').find('.slide').animate({height:0}, 500);
							$(this).removeClass('carouselheadminus').addClass('carouselheadplus');
							
						}
				});
	
	
	
})

/*quickform*/
$(document).ready(function() {	
	$("select.subject").change(function(){
						if($(this).val()=='Other'){
							$('.otherwrap').fadeIn();
							}
						else{
							$('.otherwrap').fadeOut();
							}
})

$("#quickform").submit(function(event){
            event.preventDefault();
            var name = $("input.name").val();
			var company = $("input.company").val();
			var country = $("input.country").val();
			var cnumber = $("input.cnumber").val();
            var email = $("input.email").val();
			var subject = $("select.subject").val();
			var other = $("input.other").val();
			var message = $("textarea.message").val();
			var number = $("input.number").val();
            var mydata = {
                "name": name,
				"company": company,
				"country": country,
				"cnumber": cnumber,
                "email": email,
				"subject": subject,
				"other": other,
				"message": message,
				"number": number
            };
			
			var empty = false;
			
			$('.required').each(function(){
/*				if($(this).val()==''){
					$(this).addClass('error');
					empty = true;
					}	*/
				if($(this).hasClass('email')){
					//alert('asdasd')
					}
			})
			
			if(!empty){
				$('.name,.company,.country,.cnumber,.email,.subject,.message,.number').removeClass('error');
				$('.ajaxload').fadeIn();				
				
				$.post("Ajax/handle.php",
                	mydata,
                	function(data) {
					//console.log(data.emailtest);
					if(data.capcha){
						$('#quickform').fadeOut( function(){
								$('.success').fadeIn();
														  });							
						}
					else{
						$('.notsuccess').fadeIn();	
						$('.ajaxload').fadeOut();
						}
                	},
				"json"
            	);
			}
        });
		
		$('.success button').click(function(){
					$('.notsuccess').hide();
					$('.name, .company, .country,.cnumber,.email, .subject, .message, .other, .number').val('');
					$('.success').fadeOut( function(){
								$('#quickform').fadeIn();	
								$('.ajaxload').hide();
								$('.otherwrap').hide();
														  });				 
									 })
		$('.name, .company, .country, .cnumber,.email, .subject, .message, .number').blur(function(){
										if($(this).val()!=''){
												$(this).removeClass('error')
											}					  
		})	
		
		
		
$("#jobsform").submit(function(event){
            event.preventDefault();
            var name = $("input.name").val();
			var surname = $("input.surname").val();
			var age = $("input.age").val();
			var education = $("select.education").val();
            var cell = $("input.cell").val();
			var email = $("input.email").val();
			var position = $("input.position").val();
			var othernotes = $("textarea.othernotes").val();
			var number = $("input.number").val();
            var mydata = {
                "name": name,
				"surname": surname,
				"age": age,
				"education": education,
                "cell": cell,
				"email": email,
				"position": position,
				"othernotes": othernotes,
				"number": number
            };
			
			$('.required').each(function(){
				if($(this).val()==''){
					$(this).addClass('error');
					}										 
			})
			
			if(name == "" || surname == "" || age == "" || education == "" || cell == "" || email == "" || position == "" || number == ""){}
			else{
				$('.name,.surname,.age,.education,.cell,.email,.position,.number').removeClass('error');
				$('.ajaxload').fadeIn();
				
				
				$.post("Ajax/handlejobs.php",
                	mydata,
                	function(data) {
					//console.log(data.emailtest);
					if(data.capcha){
						$('#jobsform').fadeOut( function(){
								$('.success').fadeIn();
								//alert(data.test)
														  });							
						}
					else{
						$('.notsuccess').fadeIn();	
						$('.ajaxload').fadeOut();
						}
                	},
				"json"
            	);
			}
        });
		
		$('.success button').click(function(){
					$('.notsuccess').hide();
					$('.name,.surname,.age,.education,.cell,.email,.position,.number').val('');
					$('.success').fadeOut( function(){
								$('#jobsform').fadeIn();	
								$('.ajaxload').hide();
								$('.otherwrap').hide();
														  });				 
									 })
		$('.name,.surname,.age,.education,.cell,.email,.position,.number').blur(function(){
										if($(this).val()!=''){
												$(this).removeClass('error')
											}					  
		})
});


$(document).ready(function(){	
var phase = 0;
//alert(parseInt($('.featuresliderwrapextend').css('left')))
setInterval(function(){
		if(phase < 2){			 
		var leftvalue = parseInt($('.featuresliderwrapextend').css('left')) - 893			 
		$('.featuresliderwrapextend').animate({left:leftvalue})	
		phase++;
		}
		else{
		$('.featuresliderwrapextend').animate({left:0})	
		phase = 0;
		}
	}, 5000)
})


$(document).ready(function(){ 

$('.conveyor').each(function(){
	var totalimages = $(this).find('img');
	var portwidth = (213*totalimages.length)+(16*totalimages.length)
	$(this).width(portwidth);
})

$(".slider").draggable({ axis: 'x', containment: '.sliderbar', scroll: false });
setInterval(function(){
var conveyorleft = -(parseInt($(".slider").css('left')) * $('.active_conveyor').width())/900;
$('.active_conveyor').css('left',conveyorleft)				 
					 }, 1)

$('.worktabs span.ourlogos').click(function(){
	$('.worktabs span.ourwebsites').removeClass('active')
	$(this).addClass('active')							   
	$('.workwrap .conveyor:eq(0)').removeClass('active_conveyor').fadeOut(function(){;
	$('.workwrap .conveyor:eq(1)').fadeIn().addClass('active_conveyor');
	})
})

$('.worktabs span.ourwebsites').click(function(){
	$('.worktabs span.ourlogos').removeClass('active')
	$(this).addClass('active')							   
	$('.workwrap .conveyor:eq(1)').removeClass('active_conveyor').fadeOut(function(){;
	$('.workwrap .conveyor:eq(0)').fadeIn().addClass('active_conveyor');
	})
})

})



$(document).ready(function(){ 
var footerlinks = $('.nav li');		
	for(var i=0;i<4;i++){
		$('.sitemap1').append($(footerlinks[i]).html())	
	}	
	for(var i=4;i<8;i++){
		$('.sitemap2').append($(footerlinks[i]).html())	
	}
	for(var i=8;i<11;i++){
		$('.sitemap3').append($(footerlinks[i]).html())	
	}
})


$(document).ready(function(){
$('.nav li a').wrapInner('<span></span>');						   
						   
$('.nav li')
		.css( {backgroundPosition: "0 50px"} )
		.hover(function(e){
			if(!$(this).hasClass('current_page_item')){				
				//$(this).hoverFlow(e.type,{backgroundPosition:"(0 0px)"}, {duration:200})
				$(this).find('span').animate({top:60}, 300, 'easeInCirc', function(){
							$(this).css('top','-35px').animate({top:0}, 300, 'easeOutBounce')										 
																	 })
				
			}
		}, function(e){
						   if(!$(this).hasClass('current_page_item')){
			//$(this).hoverFlow(e.type,{backgroundPosition:"(0 50px)"}, {duration:200})
						   }	   
})
})

$(document).ready(function(){
$('.slogan img').eq(2).animate({width:110}, 1000, 'easeOutBounce', function(){
								$('.slogan img').eq(1).animate({width:98}, 1000, 'easeOutBounce', function(){$('.slogan img').eq(0).animate({width:104}, 1000, 'easeOutBounce')})})
})
