/**
 * This is the java script libaray used for the soft-teck site
 */

$(document).ready(function(){
	
	var item_width = 240;
    var left_value = item_width * (-1);
    
    var img_width = 200;
    var img_height = 325;
    
	$('#st-slider-b1').click(function(event){
		event.preventDefault();
		var left_indent = parseInt($('.main-content ul').css('left')) + item_width;
        $('.main-content ul').animate({'left' : left_indent}, 200,function(){   
            $('.main-content li:first').before($('.main-content li:last'));          
 	        $('.main-content ul').css({'left' : left_value}); 
        }); 
        return false;
	});

    $('#st-slider-y1').click(function(event) {
    	event.preventDefault();
        var left_indent = parseInt($('.main-content ul').css('left')) - item_width;
        $('.main-content ul').animate({'left' : left_indent}, 200, function () {

            $('.main-content li:last').after($('.main-content li:first'));                 

            $('.main-content ul').css({'left' : left_value});
         
        });
                  
        //cancel the link behavior
        return false;
         
    });	
    
    var item_width_1 = 220;
    var left_value_1 = item_width_1 * (-1);
    
    $('#btn-portfolio-next').click(function(e){
    	e.preventDefault();
    	var left_indent = parseInt($('.portfolio-list').css('left')) + item_width_1;
    	$('.portfolio-list').animate({'left' : left_indent},200, function(){
            $('.portfolio-list li:first').before($('.portfolio-list li:last'));          
 	        $('.portfolio-list').css({'left' : left_value_1});     		
    	});
    });

    $('#btn-portfolio-previous').click(function(e){
    	e.preventDefault();
    	var left_indent = parseInt($('.portfolio-list').css('left')) - item_width_1;
    	$('.portfolio-list').animate({'left' : left_indent},200, function(){
            $('.portfolio-list li:first').before($('.portfolio-list li:last'));          
 	        $('.portfolio-list').css({'left' : left_value_1});     		
    	});
    });
    
    
    	
   	/*
    var img = $('.img-list');
    
    img.each(function(){
    	var w = $(this).width();
    	var h = $(this).height();
		//$('.portfolio-container')
    	var ratio = 1;
    	if(h > w){
    		ratio = h/img_height; 
    	}else{
    		ratio = w/img_width;
    	}

    	var new_width = Math.round(w/ratio);
    	var new_height = Math.round(h/ratio);

    	$(this).width(new_width);
    	$(this).height(new_height);
    	$('.portfolio-container').height(new_height + 20);
    });
    */
});

    function process_form(){
	var name = $("#c_name").val();
	if(name == ''){
		$("#c_name").addClass('required_field');
		$("#c_name").focus();
		return false;
	}else{
		$("#c_name").removeClass('required_field');
	}
	
	var email = $("#c_email").val();


	

	var company = $("#c_company").val();
	if(company == ''){
		$("#c_company").addClass('required_field');
		$("#c_company").focus();
		return false;		
	}else{
		$("#c_company").removeClass('required_field');
	}
	
	if(email == ''){
		$("#c_email").addClass('required_field');
		$("#c_email").focus();
		return false;		
	}else{
		$("#c_email").removeClass('required_field');
	}

	var phone = $("#c_phone").val();
	if(phone == ''){
		$("#c_phone").addClass('required_field');
		$("#c_phone").focus();
		return false;		
	}else{
		$("#c_phone").removeClass('required_field');
	}	
	

	
	var message = $("#c_message").val();
	message = $.trim(message);
	if(message == ""){
		$("#c_message").addClass('required_field');
		$("#c_message").focus();
		return false;		
	}else{
		$("#c_message").removeClass('required_field');
	}
	
	var category = $("#c_category").val();

	
	
	var html = "<p><strong>Name : </strong>" + name + "</p>";
	html += "<p><strong>Email : </strong>" + email + "</p>";
	html += "<p><strong>Phone : </strong>" + phone + "</p>";
	html += "<p><strong>Company : </strong>" + company + "</p>";
	html += "<p><strong>Category: </strong>" + category + "</p>";
	html += "<p>" + message + "</p>"; 
	
	$.ajax({
      		url: "http://www.soft-teck.com/wp-admin/admin-ajax.php",
      		type: "POST",
      		data: "action=send_mail&to=" + email + "&message=" + html,
      		success: function(data)	{
      			var html = "<p class=\"confirmation\">Thankyou for getting in touch.  We will get back to you as soon as we can.";
      			$(".contact_form").html(html);
      		}
  	});
	return false;
    }

function get_user_location(ip_address){
	alert(ip_address);
	var url = "http://ipinfodb.com/ip_query2.php?output=json&callback=?&ip=" + ip_address ;	
	
	$.getJSON(url, function(data){
   
   		console.log(data);
    	if(data.Locations[0].Status == "OK"){

        	var location = data.Locations[0]
        	var city = location.City;
        	var country = location.CountryName;
        	var region = location.RegionName
       
        	var output = "Your location is: "+ city+ ", "+region+ " "+ country;
        	alert(output);
    	}
   
	});
}



