(function($){	
	
	// -------------------------------------------------------------------------------------------------------
	// Form Validation script - used by the Contact Form script
	// -------------------------------------------------------------------------------------------------------
	
	function validateMyAjaxInputs() {

		$.validity.start();
		// Validator methods go here:
		$("#name").require();
		$("#email").require().match("email");
		$("#subject").require();	

		// End the validation session:
		var result = $.validity.end();
		return result.valid;
	}
	
	// -------------------------------------------------------------------------------------------------------
	// Form Clear
	// -------------------------------------------------------------------------------------------------------
	
	$.fn.clearForm = function() {
	  return this.each(function() {
	 var type = this.type, tag = this.tagName.toLowerCase();
	 if (tag == 'form')
	   return $(':input',this).clearForm();
	 if (type == 'text' || type == 'password' || tag == 'textarea')
	   this.value = '';
	 else if (type == 'checkbox' || type == 'radio')
	   this.checked = false;
	 else if (tag == 'select')
	   this.selectedIndex = -1;
	  });
	};

	$(document).ready(function(){
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////	
        $(".ticker").newsTicker(5000);					   
		$('form').validationEngine();
        scroll2();
        if ($('.kayanleft').length){
            $('.kayanleft').jcarousel({
                wrap: 'circular',
                auto: ($('.kayanleft li').length>3)?2:0,
                scroll:1,
                animation:'normal'
            });
        }
		// -------------------------------------------------------------------------------------------------------
		// Dropdown Menu
		// -------------------------------------------------------------------------------------------------------
		
		$("ul#dropdown-menu li").hover(function () {
												 
			$(this).addClass("hover");
			$('ul:first', this).css({visibility: "visible",display: "none"}).slideDown(200);
		}, function () {
			
			$(this).removeClass("hover");
			$('ul:first', this).css({visibility: "hidden"});
		});
		
		if ( ! ( $.browser.msie && ($.browser.version == 6) ) ){
			$("ul#dropdown-menu li ul li:has(ul)").find("a:first").addClass("arrow");
		}
								
		// -------------------------------------------------------------------------------------------------------
		// Hover over Services Overview + make entire service overview clickable
		// -------------------------------------------------------------------------------------------------------
		
		$(".services-overview-overlay").hide();
		
		 $("#services-overview li").hover(
			  function(){$(this).find('.services-overview-overlay').show();},
			  function(){$(this).find('.services-overview-overlay').hide();}
			);
		 
		 $("#services-overview li").click(function(){
			 window.location=$(this).find("a").attr("href");
			 return false;
		});
		
		// -------------------------------------------------------------------------------------------------------
		// Contact Form 
		// -------------------------------------------------------------------------------------------------------
		
		$("form").submit(function () {
											
			if ($(this).validationEngine('validate')){ //  procced only if form has been validated ok with validity validateMyAjaxInputs()
				var str = $(this).serialize();
				$.ajax({
					type: "POST",
					url: $(this).attr('action'),
					data: str,
                    dataType:'json',
					success: function (msg) {
						$("#formstatus").ajaxComplete(function (event, request, settings) {
							if (msg.success) { // Message Sent? Show the 'Thank You' message
								result = '<div class="successmsg">'+msg.msg+'</div>';
								$(this).clearForm();
							} else {
								result = '<div class="errormsg">'+msg.msg+'</div>';
							}
							$(this).html(result);
						});
					}
		
				});
				return false;
			}
		});
		
		// -------------------------------------------------------------------------------------------------------
		// Protfolio Fade 
		// -------------------------------------------------------------------------------------------------------
		
		if ($.browser.msie && $.browser.version < 7) return;

			$(".portfolio-item-preview img").fadeTo(1, 1);
			$(".portfolio-item-preview img").hover(
			
			function () {
				$(this).fadeTo("fast", 0.80);
			}, function () {
				$(this).fadeTo("slow", 1);
			});

	//////////////////////////////////////////////////////////////////////////////////////////////////////////////	
	});
    
})(window.jQuery);	
i2 = 0;
var speed2 = 1;
var t2;
function scroll2() {
    i2 = i2 + speed2;
    //div2.scrollTop = i2;
    $('.kayan').scrollTop(i2);
    //alert(i2+ ' - ' +div2.scrollTop);
    if (i2 > $('.kayan').scrollHeight - 50) {i2 = 0;}
        t2=setTimeout("scroll2()",30);
}

function scheduleScroll2(){
    t2 = setTimeout("scroll2()",5000);
}


function addEvent(obj, evType, fn){
    alert(evType);
    if (obj.addEventListener){
        obj.addEventListener(evType, fn, false);
        return true;
    } else if (obj.attachEvent){
        var r = obj.attachEvent("on"+evType, fn);
        return r;
    } else {
        return false;
    }
}
// non jQuery scripts below
