var myTime = 0;


$(document).ready(function () {
	
    liveElements();
    QueryLoader.selectorPreload = "#main";
    QueryLoader.init();
	
	
    function liveElements() {
       
if((!navigator.userAgent.match(/iPhone/i)) && (!navigator.userAgent.match(/iPod/i)) && !navigator.userAgent.match(/Blackberry/i) && !navigator.userAgent.match(/Android/i)) {
	if ($('form').length != 0) {
            $('form').jqTransform({
                imgPath: 'jqtransformplugin/img/'
            });
        }
		
		 if ($('#items img').length != 0) {
            $("#items img").simpletooltip();
        }
	}		
		
      
        if ($('#cycle').length != 0) {
            $('#cycle').cycle({
                fx: 'fade',
                speed: 'slow',
                timeout: 8000,
                next: '#next',
                prev: '#prev'
            });
        }
        if ($('#cycle-contact').length != 0) {
            $('#cycle-contact').cycle({
                fx: 'fade',
                speed: 'slow',
                timeout: 6000
            });
        }
        if ($('.press').length != 0) {
            $(".press").masonry({
                columnWidth: 190,
                singleMode: false,
                itemSelector: ".leading"
            });
        }
  /*      if ($('#homeSlider').length != 0) {
            $('#homeSlider').oSlider({
                autoStart: true,
                pauseTime: 6000,
                animSpeed: 400,
                pauseOnHover: true
            });
        }*/
		
			//console.log("liveeLEM")
		myTime = 0;
        postionMe(myTime);
    }
    $(window).resize(function () {
        postionMe(myTime);
    });
	
	 $(window).scroll(function () {
        postionMe(myTime);
    });
});


function postionMe(myTime) {
	//console.log("position")
    var myFooter = $('#footer');
    var myHeaderHeight = $('#header').outerHeight(true) + $('#nav2').outerHeight(true) + $('#nav3').outerHeight(true)
    var centerTop = ($(window).height() - $('#content-wrap').height()) / 2 + $(window).scrollTop() + myHeaderHeight / 2 - $('#footer').height() / 2 ;
    jQuery.fn.center = function () {
        this.css("position", "absolute");
        this.stop().animate({
            top: centerTop + "px",
            easing: 'easeInOutQuint'
        }, myTime, "easeInOutQuint");
        this.css("left", ($(window).width() - this.width()) / 2 + $(window).scrollLeft() + "px");
        return this;
    }
    jQuery.fn.centerNormal = function () {
        this.css("position", "absolute");
        this.css("left", ($(window).width() - this.width()) / 2 + $(window).scrollLeft() + "px");
        this.stop().animate({
            top: myHeaderHeight + "px",
            easing: 'easeInOutQuint'
        }, myTime, "easeInOutQuint");
        return this;
    }
   /* jQuery.fn.centerCenter = function () {
        this.css("position", "absolute");
        this.css("top", ($(window).height() - this.height()) / 2 + $(window).scrollTop() + "px");
        this.css("left", ($(window).width() - this.width()) / 2 + $(window).scrollLeft() + "px");
        return this;
    }*/
    if ($('#homeSlider').length != 0) {
        myContent = $('#content')
        $('#content-wrap').remove();
    } else {
        myContent = $('#content-wrap')
    }
   // $('#preloader').centerCenter();
    if ($(window).height() - ($('#footer').outerHeight(true) + myHeaderHeight) > myContent.outerHeight(true)) {
		/*console.log("1")*/
        $('#content-wrap').center();
        $('#homeSlider').stop().animate({
            top: ($(window).height() - $('#homeSlider').height()) / 2 + $(window).scrollTop() + myHeaderHeight / 2 - $('#footer').height() - 9 + "px",
            easing: 'easeInOutQuint'
        }, myTime, "easeInOutQuint");
		/*
        $('#footer').css({
            position: "absolute"
        })
        $('#footer').stop().animate({
            top: ($(window).height() - 1) + $(window).scrollTop() - $('#footer').height() + "px",
            easing: 'easeInOutQuint'
        }, myTime, "easeInOutQuint");*/
    } else {
			/*console.log("2")*/
        $('#content-wrap').centerNormal();/*
        $('#footer').css({
            position: "absolute",
            top: (myContent.height() + myHeaderHeight) + "px"
        })*/
        $('#homeSlider').css({
            top: "4px"
        })
    }/*
    $('#footer').css({
        left: ($(window).width() - $('#footer').width()) / 2 + $(window).scrollLeft() + "px"
    })*/
}





/*// mobiles
	if( navigator.userAgent.match(/Android/i) ||
	navigator.userAgent.match(/webOS/i) ||
	navigator.userAgent.match(/iPhone/i) ||
	navigator.userAgent.match(/iPod/i) ||
	navigator.userAgent.match(/Blackberry/i)
){
	// ... none
}
else{
	 if ($('form').length != 0) {
            $('form').jqTransform({
                imgPath: 'jqtransformplugin/img/'
            });
        }
		
		 if ($('#items img').length != 0) {
            $("#items img").simpletooltip();
        }
		
}
	*/	
