function check_viewport(css) {

 var viewportwidth;
 var viewportheight;
 
 // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
 
 if (typeof window.innerWidth != 'undefined')
 {
      viewportwidth = window.innerWidth,
      viewportheight = window.innerHeight
 }
 
// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)

 else if (typeof document.documentElement != 'undefined'
     && typeof document.documentElement.clientWidth !=
     'undefined' && document.documentElement.clientWidth != 0)
 {
       viewportwidth = document.documentElement.clientWidth,
       viewportheight = document.documentElement.clientHeight
 }
 
 // older versions of IE
 
 else
 {
       viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
       viewportheight = document.getElementsByTagName('body')[0].clientHeight
 }
 
 if (css) {
 	if ( viewportheight<643) {
	 	$('#footer .webby').addClass('webbystatic');
	 	$('body').addClass('b_hidden');
	 	//$('#wrapper').addClass('wrapper_static');
	 	//$('#wrapper').css('margin-top', ((viewportheight-480)/2)+'px');
	 } else {
	 	$('#footer .webby').removeClass('webbystatic');
	 	$('body').removeClass('b_hidden');
	 	//$('#wrapper').removeClass('wrapper_static');
	 	 //if ($('#wrapper').offset().top>98) { $('#wrapper').css('margin-top', '-240px');}
	 }

	 
 } else {
	 if (viewportheight<643) {
	 	//$('#footer').append('<div class="webby webbystatic"><div class="web_mouse" onmouseover="$(this).css(\'width\', \'158px\')" onmouseout="$(this).css(\'width\', \'14px\')"></div><div class="web_mouse_over"><a href="http://www.adysign.com/" title="adysign"><span>adysign</span></a><a href="mailto:skera76@gmail.com" title="arek-s" class="mail_link"><span>skera76@gmail.com</span></a></div></div>');
	 	$('#footer').append('<div class="webby webbystatic"><div class="web_mouse" onmouseover="$(this).css(\'width\', \'158px\')" onmouseout="$(this).css(\'width\', \'14px\')"></div><div class="web_mouse_over"><a href="http://www.adysign.com/" title="adysign"><span>adysign</span></a><a href="mailto:skera76@gmail.com" title="arek-s" class="mail_link"><span>skera76@gmail.com</span></a></div></div>');
	 	$('body').addClass('b_hidden');
	 	//$('#wrapper').addClass('wrapper_static');
	 		//$('#wrapper').css('margin-top', ((viewportheight-480)/2)+'px');
	 } else {
	 	$('#footer').append('<div class="webby"><div class="web_mouse" onmouseover="$(this).css(\'width\', \'158px\')" onmouseout="$(this).css(\'width\', \'14px\')"></div><div class="web_mouse_over"><a href="http://www.adysign.com/" title="adysign"><span>adysign</span></a><a href="mailto:skera76@gmail.com" title="arek-s" class="mail_link"><span>skera76@gmail.com</span></a></div></div>');
	 	//$('#wrapper').removeClass('wrapper_static');
	 	 //if ($('#wrapper').offset().top>98) { $('#wrapper').css('margin-top', '-240px');}
	 }
	 
	
	 
 }
 
 
 if (navigator.userAgent.match(/iPad/i) == null && navigator.userAgent.match(/iPhone/i) == null && navigator.userAgent.match(/Android/i) == null) {
	 if (viewportheight<=676) {
	 	$('#wrapper').addClass('wrapper_relative');
	 } else {
	 	$('#wrapper').removeClass('wrapper_relative');
	 	$('#wrapper').css('margin-top', '-240px')
	 }
	 
	 if (viewportwidth<=984) {
	 	$('#wrapper').addClass('wrapper_relative2');
	 } else {
	 	$('#wrapper').removeClass('wrapper_relative2');
	 }
	 /*
	 if (viewportwidth<=928) {
	 	$('#footer').addClass('footer_relative');
	 } else {
	 	$('#footer').removeClass('footer_relative');
	 }
	 */
 } else {
 	$('body').css('min-height', '100%');
 	$('#wrapper').addClass('wrapper_relative');
 	$('#footer .webby').addClass('webbystatic');
 }
	
 	return viewportheight;
}

if (navigator.userAgent.match(/iPad/i) == null && navigator.userAgent.match(/iPhone/i) == null && navigator.userAgent.match(/Android/i) == null) {
	$(window).resize(function() {
	  check_viewport('css'); 
	});
}




$(document).ready(function() {

	viewportheight = check_viewport(); 
	
	$("a[href*='http://']:not([href*='"+location.hostname+"'])").attr("target","_blank");
	
	$('.webby').hover (function() {
		$(this).children('.web_mouse_over').fadeToggle('slow');
	});
	
	$('.menu a').click (function() {
		if (!$(this).hasClass('active')) {
			$(this).addClass('blink');
			$(this).addClass('active');
			var act_link = $(this);
			setTimeout(function(){
				act_link.removeClass('blink');
			}, 100);
			
			$('.menu a').not(this).each(function() {
				$(this).removeClass('active').removeClass('vactive');
			})
		

			if ($('#mask').position().top<='-479') {
				
				$('#mask').animate({
			    top: '0'
			  }, 250, function() {
			  	var data = 'p='+get_project(act_link.attr('href'));
			    $.ajax({
						url: "ajx.php",
						type: "GET",
						data: data,
						success: function(html){
							$('#content_load').html(html);
						},
						complete: function(){
							$('#content_load').fadeIn(200);
						}
					});
			  });
			} else {
				var data = 'p='+get_project(act_link.attr('href'));
			    $.ajax({
						url: "ajx.php",
						type: "GET",
						data: data,
						success: function(html){
							$('#content_load').fadeOut(100);
							setTimeout(function(){
								$('#content_load').html(html);
							}, 100);
						},
						complete: function(){
							$('#content_load').fadeIn(100);
						}
					});
			}
		
		}
		
	});

	
	$('.ad-gallery').adGallery(); 
	
	$('.ad-thumbs li a').click(function(){
		if ($('.ad-image-wrapper').hasClass('first')) {
			$('.pr_copy').fadeOut(200);
			setTimeout(function(){
				$('.ad-image').fadeIn(200);
			}, 200);
			setTimeout(function(){
				$('.ad-image-wrapper').removeClass('first');
			}, 400);
		}
	})
	
});	

function get_project(hash) {
	var m_hash = hash;
	var proj = m_hash.split('#');
	return proj[1];
}


	
	

