jQuery(function($) {
	$( document ).ready( function(){
		$('#our-network-button').click(function(){
			var top = parseInt($('#header').css('top').replace('px', ''));
			
			if( top == 0 ) {
				$('#header').animate({'top': '-82px'});
				$(this).removeClass('active-network-button');
			}else {
				$('#header').animate({'top': '0'});
				$(this).addClass('active-network-button');
			}
			return false;
		});
		
		
		$('.blink')
			.focus(function(){
				if( $(this).attr('value') == $(this).attr('title') ) {
					$(this).attr({ 'value': '' });
				}
			})
			.blur(function(){
				if( $(this).attr('value') == '' ) {
					$(this).attr({ 'value': $(this).attr('title') })
				}
			});
		
			
		/** Win **/
		
		/** Win Screen Height **/	
		var h = $( 'body' ).height() > $( window ).height() ? $( 'body' ).height() : $( window ).height();
		$('#win_screen').css({ 'height': h });
		
	
		/** Open Win **/
		$('a.win-mail').click(function(){
			var url = $(this).attr('href') + '?cb=' + Math.random();
			var title = $(this).attr('title');
			var download_url = $(this).parent().find('.download-button:eq(0)').attr('href');
			
			$('#win h3').html( title );
			$('#win #download-button').attr({ 'href': download_url });
			
			open_window();
			$('#win-frame').attr({ 'src': url });
			
			return false;
		});
		
		/** Close Win **/
		$( '#win_screen, #close-win-button' ).click(function(){ close_window(); return false;});
		
		
	
	});
	
	//function to fix height of iframe!
	var calcHeight = function() {
	    var topbarDimensions = $('#preview-bar').height();
	    $('#preview-frame').height($(window).height() - topbarDimensions -1);
	}
	  
	$(document).ready(function() {
	    calcHeight();
	});
	  
	$(window).resize(function() {
	    calcHeight();
	}).load(function() {
		calcHeight();
	});
	
	function set_top_position(){
		var win_height = 670;
		
		var top_position = $(document).scrollTop() + $(window).height()/2 - win_height/2;
		$('#win-holder').css({ 'top': top_position+'px' });
	}
	
	function open_window() {
		set_top_position();
		
		$( '#win_screen' ).show().css({ 'opacity': 0 });
		$( '#win_screen' ).fadeTo( 'dev', 0.8, function(){
			$( '#win' ).show();
			$( '#win_screen' ).show();
		});
		
		
	}
	function close_window() {
		
		$('#win-frame').attr({ 'src': 'about:blank' });
		
		$( '#win' ).hide();
		$( '#win_screen' ).fadeTo( 'dev', 0, function(){
			$( this ).hide();
		});
		return false;
	}
});