$(document).ready(function(){

	/*$('.calendar_from input').datepicker( { altFormat: 'yy-mm-dd',
		showOn: 'button',
		buttonImage: '',
		//buttonImageOnly: true
		buttonText: '&nbsp;'
	} );
	$('.calendar_to input').datepicker( { altFormat: 'yy-mm-dd',
		showOn: 'button',
		buttonImage: '',
		//buttonImageOnly: true
		buttonText: '&nbsp;'
	} );*/
	
	
	var dates = $( ".calendar" ).datepicker({
		defaultDate: "+1w",
		showOn: 'button',
		buttonImage: '',
		buttonText: '&nbsp;',
		dateFormat: 'dd.mm.yy',
		firstDay: 1
		
		//changeMonth: true,
		//numberOfMonths: 3,
	});
	

// ===== info =====
    setTimeout( function(){
    	$('.wrap_message').slideUp('normal');
    	$('.wrap_error').slideUp('normal');
	}, 5000);
	$('.wrap_message .close').click(function() {
		$(this).closest('.wrap_info').slideUp('normal');
	});
	$('.wrap_error .close').click(function() {
		$(this).closest('.wrap_info').slideUp('normal');
	});
	
	
// ===== submenu =====
	$('body').click(function() {
		$('.wrap_sub').hide();
	});
	
	$('.wrap_sub *').click(function(event){
		event.stopPropagation();
	});
	
	$('.wrap_sub .close').click(function() {
		$(this).closest('.wrap_sub').hide();
		return false;
	});
	
	$('.sub > a').click(function() {
		$('.wrap_sub').hide();
		$(this).next().show();
		return false;
	});
	

	
});


$(window).load(function() {

// ===== iframe =====
	var viewport_height = $(window).height();
	viewport_height = viewport_height - 45;
	if ( $.browser.msie ) {
		var iframe_height = viewport_height;
	}else{
		if ($.browser.opera) {
			iframe_height = $('iframe#resume').contents().find('html').height();
		} else {
			iframe_height = $('iframe#resume').contents().find('body').height();
		}
		if( viewport_height < iframe_height ){
			iframe_height = viewport_height;
		}
	}


	var href_temp = $('link[href*="style.css"]').attr('href');
	var href_end = href_temp.length - 9;
	href_temp = href_temp.substring(0, href_end );
	//href_temp.replace("style.css", "iframe.css");
	$('iframe#resume').contents().find('head').append('<link rel="stylesheet" href="'+href_temp+'iframe.css" />');
	
	$('.iframe_min').click(function() {
		$('iframe#resume').show().animate({
		    height: '120px',
		    width: '100%'
		  }, 1000, function() {
			$.scrollTo( '#anchor_resume', 500, {easing:'linear'} );
		  });
		return false;
	});
	$('.iframe_max').click(function() {
		
		
		$('iframe#resume').show().animate({
			height: iframe_height+'px',
		    width: '100%'
		  }, 1000, function() {
		    $.scrollTo( '#anchor_resume', 500, {easing:'linear'} );
		  });
		return false;
	});
	$('.iframe_close').click(function() {
		$('iframe#resume').animate({
			height: '0px',
		    width: '100%'
		  }, 1000, function() {
			$.scrollTo( '#anchor_resume', 500, {easing:'linear'} );
			$(this).hide();
		  });
		return false;
	});
	
// Working with placeholders. If placeholder is not supported adding Js support for it.
$("[placeholder]").addClass('grey_text');
if (!elementSupportsAttribute('input','placeholder')) {

    $("[placeholder]").each(function(){
      $(this).val($(this).attr('placeholder'));
    });
      
    $("[placeholder]").focus(function() {
      if($(this).val() == $(this).attr('placeholder'))
      {
        $(this).val('');
        $(this).removeClass('grey_text');
      }
      });
    $("[placeholder]").blur(function() {
      if($(this).val() == '')
      {
        $(this).val($(this).attr('placeholder'));
        $(this).addClass('grey_text');
      }
      });
}
else
  {
    // if placeholders are supported, add style change to it
    $("[placeholder]").focus(function() {
        $(this).removeClass('grey_text');
      });
    $("[placeholder]").blur(function() {
      if($(this).val() == '')
      {
        $(this).addClass('grey_text');
      }
      });
    
  }
 
  
});

function elementSupportsAttribute(element,attribute) {
    var test = document.createElement(element);
    if (attribute in test) {
        return true;
    } else {
        return false;
    }
}

