﻿var chckKey = true;

$(document).ready(function () {

    $("#mpRotator").panpaMultiSlider({
	    '$slideElement': '.slider', 
	    '$slideType': 'fade',
	    '$paginateStyle': 'normal'
    });

    $('#email').focus(function(e){  chckKey = false; });

    $('#email').blur(function(e){  chckKey = true;   });

	var elem2Query = "#header-flash";
	var elem2Hide = "#footer";
	
	//jQuery element to hide
	var jElem2Hide = $(elem2Hide);
	
	$(window).scroll(function(){ 
		
		if (isElementInView()){
			jElem2Hide.fadeOut("slow");
		}else{
			jElem2Hide.fadeIn("fast");
		}
	});

	//on load--- this is required if the page is refreshed while the  elem2Query is in view
	if (isElementInView()) jElem2Hide.fadeOut("slow");
	function isElementInView(){
		
		var jWindow = $(window);
		var jElem   = $(elem2Query);
		var pageViewTop = jWindow.scrollTop();
		var pageViewBottom = pageViewTop + jWindow.height();
		var elemTop = jElem.offset().top;
		var elemBottom = elemTop + jElem.height();
		var isInView =((elemBottom >= pageViewTop) 
				&& (elemTop <= pageViewBottom)
				&& (elemBottom <= pageViewBottom) 
				&& (elemTop >= pageViewTop));
				
		return isInView;
	};	
	$.localScroll.defaults.axis = 'x';
	$.localScroll.hash({
		target: '#body', // Could be a selector or a jQuery object too.
		queue:true,
		duration:1500
	});
	$('.headlinks').localScroll({
			target: '#body', // could be a selector or a jQuery object too.
			queue:true,
			duration:1000,
			hash:true,
			onBefore:function( e, anchor, $target ){
				// The 'this' is the settings object, can be modified
			},
			onAfter:function( anchor, settings ){
				// The 'this' contains the scrolled element (#content)
			}
		});
	$('#hovers #brand').mouseenter(
    function() {
		$('#hovers img').attr('src', '/assets/img/hovers-brand-goals.jpg');
      }
    );
	$('#hovers #brand').mouseleave(
    function() {
		$('#hovers img').attr('src', '/assets/img/hovers-about-us.jpg');
      }
    );
	$('#hovers #technical').mouseenter(
    function() {
		$('#hovers img').attr('src', '/assets/img/hovers-technical-feasibility.jpg');
      }
    );
	$('#hovers #technical').mouseleave(
    function() {
		$('#hovers img').attr('src', '/assets/img/hovers-about-us.jpg');
      }
    );
	$('#hovers #business').mouseenter(
    function() {
		$('#hovers img').attr('src', '/assets/img/hovers-business-goals.jpg');
      }
    );
	$('#hovers #business').mouseleave(
    function() {
		$('#hovers img').attr('src', '/assets/img/hovers-about-us.jpg');
      }
    );
	$('#hovers #customer').mouseenter(
    function() {
		$('#hovers img').attr('src', '/assets/img/hovers-customer-goals.jpg');
      }
    );
	
	$('#hovers #brand').mouseenter(
    function() {
		$('#hovers img').attr('src', '/assets/img/hovers-brand-goals.jpg');
      }
    );
	$('#hovers #brand').mouseleave(
    function() {
		$('#hovers img').attr('src', '/assets/img/hovers-about-us.jpg');
      }
    );
	$('#hovers #technical').mouseenter(
    function() {
		$('#hovers img').attr('src', '/assets/img/hovers-technical-feasibility.jpg');
      }
    );
	$('#hovers #technical').mouseleave(
    function() {
		$('#hovers img').attr('src', '/assets/img/hovers-about-us.jpg');
      }
    );
	$('#hovers #business').mouseenter(
    function() {
		$('#hovers img').attr('src', '/assets/img/hovers-business-goals.jpg');
      }
    );
	$('#hovers #business').mouseleave(
    function() {
		$('#hovers img').attr('src', '/assets/img/hovers-about-us.jpg');
      }
    );
	$('#hovers #customer').mouseenter(
    function() {
		$('#hovers img').attr('src', '/assets/img/hovers-customer-goals.jpg');
      }
    );
	$('#hovers #customer').mouseleave(
    function() {
	$('#hovers img').attr('src', '/assets/img/hovers-about-us.jpg');
      }
    );
	$('.footlinks').localScroll({
			target: '#body', // could be a selector or a jQuery object too.
			queue:true,
			duration:1000,
			hash:true,
			onBefore:function( e, anchor, $target ){
				// The 'this' is the settings object, can be modified
			},
			onAfter:function( anchor, settings ){
				// The 'this' contains the scrolled element (#content)
			}
		});

	$('.footlinkstr').localScroll({
			target: '#body', // could be a selector or a jQuery object too.
			queue:true,
			duration:1000,
			hash:true,
			onBefore:function( e, anchor, $target ){
				// The 'this' is the settings object, can be modified
			},
			onAfter:function( anchor, settings ){
				// The 'this' contains the scrolled element (#content)
			}
		});

	$('#hoverstr #brand').mouseenter(
    function() {
	$('#hoverstr img').attr('src', '/assets/img/hovers-brand-goals-tr.jpg');
      }
    );
	$('#hoverstr #brand').mouseleave(
    function() {
		$('#hoverstr img').attr('src', '/assets/img/hovers-about-us-tr.jpg');
      }
    );
	$('#hoverstr #technical').mouseenter(
    function() {
		$('#hoverstr img').attr('src', '/assets/img/hovers-technical-feasibility-tr.jpg');
      }
    );
	$('#hoverstr #technical').mouseleave(
    function() {
		$('#hoverstr img').attr('src', '/assets/img/hovers-about-us-tr.jpg');
      }
    );
	$('#hoverstr #business').mouseenter(
    function() {
		$('#hoverstr img').attr('src', '/assets/img/hovers-business-goals-tr.jpg');
      }
    );
	$('#hoverstr #business').mouseleave(
    function() {
		$('#hoverstr img').attr('src', '/assets/img/hovers-about-us-tr.jpg');
      }
    );
	$('#hoverstr #customer').mouseenter(
    function() {
		$('#hoverstr img').attr('src', '/assets/img/hovers-customer-goals-tr.jpg');
      }
    );
	$('#hoverstr #customer').mouseleave(
    function() {
		$('#hoverstr img').attr('src', '/assets/img/hovers-about-us-tr.jpg');
      }
    );	
});


function validate(lang) {
    var flag = true;
    var _email = $("#email").val();
    if (_email == "") {
        jQuery("#errNewsletter").show();
        if (lang == "tr") {
            jQuery("#errNewsletter span").html("Doldurulması zorunlu alan");
        }
        else { jQuery("#errNewsletter span").html("Required field"); }
        flag = false;
    }
    else {
        var emailRegexStr = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
        if (emailRegexStr.test(_email)) {
            flag = true;
        }
        else {
            jQuery("#errNewsletter").show();
            if (lang == "tr") {
                jQuery("#errNewsletter span").html("Geçersiz E-Posta Adresi");
            }
            else { jQuery("#errNewsletter span").html("Invalid E-Mail Address"); }
            flag = false;
        }
    }

    if (flag == true) {
        jQuery("#errNewsletter").hide();
    }

    return flag;
}


$(document).keypress(function (e) {
    if (chckKey == true) {
        switch (e.which) {
            case 97: $('.headlinks a.about-us').trigger('click');
                break;
            case 119: $('.headlinks a.recent-work').trigger('click');
                break;
            case 111: $('.headlinks a.our-approach').trigger('click');
                break;
            case 99: $('.headlinks a.contact').trigger('click');
                break;
            case 116: $('#footer .footlinks a.top').trigger('click');
                break;
            case 100: $('#footer .footlinkstr a.top').trigger('click');
                break;

            case 98: $('.headlinkstr a.about-us').trigger('click');
                break;
            case 121: $('.headlinkstr a.our-approach').trigger('click');
                break;
            case 105: $('.headlinkstr a.recent-work').trigger('click');
                break;
            case 108: $('.headlinkstr a.contact').trigger('click');
        }
    }
});

