﻿/*ALTUS | JAVASCRIPT ################################################*/
/*###################################################################*/
/*@Author: Tolga KILIC | http://spacesheep.net ######################*/
/*###################################################################*/

//$(function() { QueryLoader.selectorPreload = "body"; QueryLoader.init() });

$(function() {

	var $sidescroll	= (function() {
			
			// the row elements
		var $rows			= $('#container > section > article .row'),
			// we will cache the inviewport rows and the outside viewport rows
			$rowsViewport, $rowsOutViewport,
			// navigation menu links
			$links			= $('nav > a'),
			// the window element
			$win			= $(window),
			// we will store the window sizes here
			winSize			= {},
			// used in the scroll setTimeout function
			anim			= false,
			// page scroll speed
			scollPageSpeed	= 2000 ,
			// page scroll easing
			scollPageEasing = 'easeInOutExpo',
			// perspective?
			hasPerspective	= true,
			
			perspective		= hasPerspective && Modernizr.csstransforms3d,
			// initialize function
			init			= function() {
				
				// get window sizes
				getWinSize();
				// initialize events
				initEvents();
				// define the inviewport selector
				defineViewport();
				// gets the elements that match the previous selector
				setViewportRows();
				// if perspective add css
				if( perspective ) {
					$rows.css({
						'-webkit-perspective'			: 600,
						'-webkit-perspective-origin'	: '50% 0%'
					});
				}
				// show the pointers for the inviewport rows
				$rowsViewport.find('a.ss-circle').addClass('ss-circle-deco');
				// set positions for each row
				placeRows();
				
			},
			// defines a selector that gathers the row elems that are initially visible.
			// the element is visible if its top is less than the window's height.
			// these elements will not be affected when scrolling the page.
			defineViewport	= function() {
			
				$.extend( $.expr[':'], {
				
					inviewport	: function ( el ) {
						if ( $(el).offset().top < winSize.height ) {
							return true;
						}
						return false;
					}
				
				});
			
			},
			// checks which rows are initially visible 
			setViewportRows	= function() {
				
				$rowsViewport 		= $rows.filter(':inviewport');
				$rowsOutViewport	= $rows.not( $rowsViewport )
				
			},
			// get window sizes
			getWinSize		= function() {
			
				winSize.width	= $win.width();
				winSize.height	= $win.height();
			
			},
			// initialize some events
			initEvents		= function() {
				
				// navigation menu links.
				// scroll to the respective section.
				$links.on( 'click.Scrolling', function( event ) {
					
					// scroll to the element that has id = menu's href
					$('html, body').stop().animate({
						scrollTop: $( $(this).attr('href') ).offset().top
					}, scollPageSpeed, scollPageEasing );
					
					return false;
				
				});
				
				$(window).on({
					// on window resize we need to redefine which rows are initially visible (this ones we will not animate).
					'resize.Scrolling' : function( event ) {
						
						// get the window sizes again
						getWinSize();
						// redefine which rows are initially visible (:inviewport)
						setViewportRows();
						// remove pointers for every row
						$rows.find('a.ss-circle').removeClass('ss-circle-deco');
						// show inviewport rows and respective pointers
						$rowsViewport.each( function() {
							
							$(this).find('div.ss-left')
								   .css({ left   : '0%' })
								   .end()
								   .find('div.ss-right')
								   .css({ right  : '0%' })
								   .end()
								   .find('a.ss-circle')
								   .addClass('ss-circle-deco');
						
						});
					
					},
					// when scrolling the page change the position of each row	
					'scroll.Scrolling' : function( event ) {
						
						// set a timeout to avoid that the 
						// placeRows function gets called on every scroll trigger
						if( anim ) return false;
						anim = true;
						setTimeout( function() {
							
							placeRows();
							anim = false;
							
						}, 10 );
					
					}
				});
			
			},
			// sets the position of the rows (left and right row elements).
			// Both of these elements will start with -50% for the left/right (not visible)
			// and this value should be 0% (final position) when the element is on the
			// center of the window.
			placeRows		= function() {
				
					// how much we scrolled so far
				var winscroll	= $win.scrollTop(),
					// the y value for the center of the screen
					winCenter	= winSize.height / 2 + winscroll;
				
				// for every row that is not inviewport
				$rowsOutViewport.each( function(i) {
					
					var $row	= $(this),
						// the left side element
						$rowL	= $row.find('div.ss-left'),
						// the right side element
						$rowR	= $row.find('div.ss-rightx'),
						// top value
						rowT	= $row.offset().top;
					
					// hide the row if it is under the viewport
					if( rowT > winSize.height + winscroll ) {
						
						if( perspective ) {
						
							$rowL.css({
								'-webkit-transform'	: 'translate3d(-75%, 0, 0) rotateY(-90deg) translate3d(-75%, 0, 0)',
								'opacity'			: 0
							});
							/*$rowR.css({
								'-webkit-transform'	: 'translate3d(75%, 0, 0) rotateY(90deg) translate3d(75%, 0, 0)',
								'opacity'			: 0
							});*/
							$rowR.css({ right 		: '-50%' });
						
						}
						else {
						
							$rowL.css({ left 		: '-50%' });
							$rowR.css({ right 		: '-50%' });
						
						}
						
					}
					// if not, the row should become visible (0% of left/right) as it gets closer to the center of the screen.
					else {
						
						// row's height
						var rowH	= $row.height(),
							// the value on each scrolling step will be proporcional to the distance from the center of the screen to its height
							factor 	= ( ( ( rowT + rowH / 2 ) - winCenter ) / ( winSize.height / 2 + rowH / 2 ) ),
							// value for the left / right of each side of the row.
							// 0% is the limit
							val		= Math.max( factor * 50, 0 );
							
						if( val <= 0 ) {
							
							if($($row + ':not("article")')) {
								$('nav ul li ul li a.link-active').removeClass('link-active');
								$('a[href=#'+$row.closest('article').attr('id')+']').addClass('link-active');
							}
							
							// when 0% is reached show the pointer for that row
							if( !$row.data('pointer') ) {
							
								$row.data( 'pointer', true );
								$row.find('.ss-circle').addClass('ss-circle-deco');
							
							}
						
						}
						else {
							
							// the pointer should not be shown
							if( $row.data('pointer') ) {
								
								$row.data( 'pointer', false );
								$row.find('.ss-circle').removeClass('ss-circle-deco');
							
							}
							
						}
						
						// set calculated values
						if( perspective ) {
							
							var	t		= Math.max( factor * 75, 0 ),
								r		= Math.max( factor * 90, 0 ),
								o		= Math.min( Math.abs( factor - 1 ), 1 );
							
							$rowL.css({
								'-webkit-transform'	: 'translate3d(-' + t + '%, 0, 0) rotateY(-' + r + 'deg) translate3d(-' + t + '%, 0, 0)',
								'opacity'			: o
							});
							/*$rowR.css({
								'-webkit-transform'	: 'translate3d(' + t + '%, 0, 0) rotateY(' + r + 'deg) translate3d(' + t + '%, 0, 0)',
								'opacity'			: o
							});*/
							$rowR.css({ right 	: - val + '%' });
						
						}
						else {
							
							$rowL.css({ left 	: - val + '%' });
							$rowR.css({ right 	: - val + '%' });
							
						}
						
					}	
				
				});
			
			};
		
		return { init : init };
	
	})();
	
	$sidescroll.init();
	
});

/*Document Ready*/
$(document).ready(function () {
    //    $("#FuCV").rules("add", { required: true, accept: 'doc'| 'pdf' });
    $("#form").validate();
    var $header = $('#header');

    //$("#RbtnAppType label").attr("class", "label_radio");

    $('.label_radio').click(function () {
        $('#form').slideDown();
    })

    //Parallax
    /*
    $('.top').addClass('hidden');
    $.waypoints.settings.scrollThrottle = 30;
    $('#wrapper').waypoint(function (event, direction) {
    $('.top').toggleClass('hidden', direction === "up");
    }, {
    offset: '-100%'
    }).find('#main-nav-holder').waypoint(function (event, direction) {
    $(this).parent().toggleClass('sticky', direction === "down");
    event.stopPropagation();
    });
    */
    //End of Parallax

    $('.top').addClass('hidden');
    $.waypoints.settings.scrollThrottle = 30;
    $('#wrapper').waypoint(function (event, direction) {
        $('.top').toggleClass('hidden', direction === "up");
    }, {
        offset: '-100%'
    }).find('#main-nav-holder').waypoint(function (event, direction) {
        $(this).parent().toggleClass('sticky', direction === "down");
        event.stopPropagation();
    });

    // Register each section as a waypoint.
    $('section#container > section').waypoint({ offset: '20%' });

    $('#wrapper').find('#main-nav').waypoint(function (event, direction) {
        $('.top').toggleClass('hidden', direction === "up");
        $(this).parent().toggleClass('sticky', direction === "down");
        event.stopPropagation();
    });

    // The same for all waypoints
    $('body').delegate('section#container > section', 'waypoint.reached', function (event, direction) {
        var $active = $(this);

        if (direction === "up") {
            $active = $active.prev();
        }
        if (!$active.length) $active.end();

        $('.section-active').removeClass('section-active');
        $active.addClass('section-active');

        $('.link-active').removeClass('link-active');
        $('a[href=#' + $active.attr('id') + ']').addClass('link-active');
    });


    // Negates the flash of non-active nav.
    $('body > header nav a').click(function () {
        $(this).addClass('link-active');
    }).eq(0).addClass('link-active');

    // Wicked credit to
    // http://www.zachstronaut.com/posts/2009/01/18/jquery-smooth-scroll-bugs.html
    var scrollElement = 'html, body';
    $('html, body').each(function () {
        var initScrollTop = $(this).attr('scrollTop');
        $(this).attr('scrollTop', initScrollTop + 1);
        if ($(this).attr('scrollTop') == initScrollTop + 1) {
            scrollElement = this.nodeName.toLowerCase();
            $(this).attr('scrollTop', initScrollTop);
            return false;
        }
    });

    // Smooth scrolling for internal links
    $("a[href^='#']").click(function (event) {
        event.preventDefault();

        var $this = $(this),
		target = this.hash,
		$target = $(target);

        $(scrollElement).stop().animate({
            'scrollTop': $target.offset().top
        }, 500, 'swing', function () {
            window.location.hash = target;
        });

    });

    $(window).on("load resize", setHeader);

    function setHeader() {
        $header.height($(window).height() - 80);
    }

    setHeader();

    //Slider
    $('#banner-rotator').royalSlider({
        slideTransitionSpeed: 400,
        slideTransitionEasing: "easeInOutCubic",
        controlNavEnabled: false,
        slideshowEnabled: false,
        slideshowDelay: 6000,
        hideArrowOnLastSlide: false,
        imageAlignCenter: true,
        slideSpacing: 0,
        imageAlignCenter: false,
        welcomeScreenEnabled: false,
        welcomeScreenShowSpeed: 500
    });
    //End of Slider

    //Contact Tab
    $(".menuContact > li").click(function (e) {
        $(".menuContact > li").removeClass('active');
        $this = $(this);
        $this.addClass('active');
        $('.menuContent').removeClass('active');
        var currentTab = $('.menuContent.' + $this.attr('id'));
        currentTab.addClass('active');

        return false;
    });
    //End of Contact Tab


    // Google Maps
    /*
    function initialize(canvasID, lat, lon, zoom) {
		
    var myOptions = {
    zoom: zoom,
    center: new google.maps.LatLng(lat, lon),
    mapTypeId: google.maps.MapTypeId.ROADMAP
    }
    var map = new google.maps.Map(document.getElementById(canvasID),
    myOptions);

    var image = 'http://google-maps-icons.googlecode.com/files/findajob.png';
		
    var infowindow = new google.maps.InfoWindow({
    content: '<strong>Altus</strong>',
    maxWidth: 200
    });
    var myLatLng = new google.maps.LatLng(lat, lon);
    var marker = new google.maps.Marker({
    position: myLatLng,
    map: map,
    icon: image
    });

    google.maps.event.addListener(marker, 'click', function () {
    infowindow.open(map, marker);
    });
		
    }
    */

    function initialize(canvasID, lat, lon, zoom, infoHTML) {
        var secheltLoc = new google.maps.LatLng(lat, lon);

        var myMapOptions = {
            zoom: zoom
            ,scrollwheel: false
			, center: secheltLoc
			, mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        var theMap = new google.maps.Map(document.getElementById(canvasID), myMapOptions);


        var marker = new google.maps.Marker({
            map: theMap,
            draggable: false,
            position: new google.maps.LatLng(lat, lon),
            visible: true,
            icon: '/images/map_icon.png'
        });

        var boxText = document.createElement("div");
        boxText.style.cssText = "border: 1px solid #ABABAB; margin-top: 8px; background: #fff; padding: 5px;";
        boxText.innerHTML = infoHTML;

        var myOptions = {
            content: boxText
			, disableAutoPan: false
			, maxWidth: 0
			, pixelOffset: new google.maps.Size(-140, 0)
			, zIndex: null
			, boxStyle: {
			    background: "url('tipbox.gif') no-repeat"
			  , opacity: 0.75
			  , width: "300px"
			}
			, closeBoxMargin: "15px 7px 2px 2px"
			, closeBoxURL: "http://www.google.com/intl/en_us/mapfiles/close.gif"
			, infoBoxClearance: new google.maps.Size(1, 1)
			, isHidden: false
			, pane: "floatPane"
			, enableEventPropagation: false
        };

        google.maps.event.addListener(marker, "click", function (e) {
            ib.open(theMap, this);
        });

        var ib = new InfoBox(myOptions);
        //ib.open(theMap, marker);
    }


    initialize('map_canvas_1', '39.871804', '32.744751', 12, '<dl class="infoContact" style="float:none;"><dt>Genel Müdürlük-Ankara</dt><dd>Cyberpark Tepe Binası 5.Blok 1.Kat No:2 Bilkent&ndash;Ankara</dd><dd>Tel: 0312 266 24 54 - 0312 266 24 54</dd><dd>Faks: 0312 266 24 87</dd></dl>');
    initialize('map_canvas_2', '39.947779', '32.768612', 13, '<dl class="infoContact"><dt>Ostim Şube-Ankara</dt><dd>ATB İş Merkezi I Blok No:253 Yenimahalle - Ankara</dd><dd>Tel: 0312 387 11 69 - 0312 387 11 69</dd><dd>Faks: 0312 387 00 39</dd></dl>');
    initialize('map_canvas_3', '40.996567', '29.142919', 14, '<dl class="infoContact"><dt>Bölge Müdürlüğü-İstanbul</dt><dd>Yukarı Dudullu Akıncı Sokak No: 24 Kat: 2 Ümraniye - İstanbul</dd><dd>Tel: 0216 415 55 01 &ndash; 0216 415 55 01</dd><dd>Faks: 0216 415 55 16</dd></dl>');

    //Colorbox
    $(".lightbox").colorbox({ rel: 'certificate01' });


    /*Font*/
    Cufon.replace('.cufon-replace', { hover: true })
				  ('h1 span.headRefer', { hover: true })
				  ('h1 span.headBlog', { hover: true })
                  ('h1 span.headContact', { hover: true })
				  ('.sloganHeading', { hover: true })
				  ('#atm-hizmetleri .item13', { hover: true })
				  ('#atm-hizmetleri .item14', { hover: true })
				  ('#atm-hizmetleri .item15', { hover: true })
				  ('#hizmet-sahamiz .item16', { hover: true })
				  ('#hizmet-sahamiz .item17', { hover: true })
				  ('#hizmet-sahamiz .item18', { hover: true })
				  ('#hizmet-sahamiz .item19', { hover: true })
				  ('#hizmet-sahamiz .item20', { hover: true })
				  ('#hizmet-sahamiz .item21', { hover: true })
				  ('#masaustu-yonetim-hizmetleri .item17', { hover: true })
				  ('#masaustu-yonetim-hizmetleri .item18', { hover: true })
				  ('#masaustu-yonetim-hizmetleri .item19', { hover: true })
				  ('#masaustu-yonetim-hizmetleri .item37', { hover: true })
				  ('#masaustu-yonetim-hizmetleri .item38', { hover: true })
				  ('#masaustu-yonetim-hizmetleri .item39', { hover: true })
				  ('#ag-yonetim-hizmetleri .item06', { hover: true })
				  ('#ag-yonetim-hizmetleri .item07', { hover: true })
				  ('#ag-yonetim-hizmetleri .item08', { hover: true })
				  ('#teknik-kadromuz .item20', { hover: true })
				  ('#teknik-kadromuz .item21', { hover: true })
				  ('#teknik-kadromuz .item22', { hover: true })
				  ('#teknik-kadromuz .item23', { hover: true })
				  ('#yazilim-gelistirme .item03', { hover: true })
				  ('#yazilim-gelistirme .item04', { hover: true })
				  ('#yazilim-gelistirme .item11', { hover: true })
				  ('#yazilim-gelistirme .item12', { hover: true })
				  ('#guvenlik-acigi .item02', { hover: true })
				  ('#tumlesik-iletisim-cozumleri .item02', { hover: true })
				  ('#tumlesik-iletisim-cozumleri .item03', { hover: true })
				  ('#tumlesik-iletisim-cozumleri .item04', { hover: true })
				  ('#tumlesik-iletisim-cozumleri .item22', { hover: true })
				  ('#tumlesik-iletisim-cozumleri .item23', { hover: true })
				  ('#tumlesik-iletisim-cozumleri .item24', { hover: true })
				  ('#tumlesik-iletisim-cozumleri .item25', { hover: true })
				  ('#bilgi-guvenligi-cozumleri .item02', { hover: true })
				  ('#bilgi-guvenligi-cozumleri .item04', { hover: true })
				  ('#sistem-yonetimi .item02', { hover: true })
				  ('#sistem-yonetimi .item03', { hover: true })
				  ('#sistem-yonetimi .item04', { hover: true })
				  ('#sistem-yonetimi .item21', { hover: true })
				  ('#sistem-yonetimi .item22', { hover: true })
				  ('#sistem-yonetimi .item23', { hover: true })
				 ;
    /*Font*/


});
/*End of Document Ready*/

