var baseURL = 'http://www.easyquit.co.il/';
var audioIntroURL = baseURL+'audio/h_intro.mp3';
$(document).ready( function() {
	$('#block1 > .vid').fancybox({
		ajax: { type: "POST", data: "action=getIntro" }
	});
	$('#block1 > .aud').fancybox({ title: 'שיחת הכרות', content: "<div id='myContent'>Flash Required</div><script type='text/javascript'>swfobject.embedSWF('player.swf', 'myContent', '470', '24', '9.0.115', 'expressInstall.swf', { 'file': '"+audioIntroURL+"', 'autostart': 'true' }, { 'wmode': 'opaque' } );</script>" });
});

function pop(name,w,h)	{
	var L = (window.screen.width - w) / 2;
	var T = (window.screen.height - h) / 2;

	window.open( name, "", "left=" + L + ",top=" + T + ",width=" + w + ",height=" + h + ",toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,fullscreen=no");
}

function isValidEmail( email ) {
	var	checkStr = email;
	var	emailValid = false;
	var	emailAt	= false;
	var	emailPeriod	= false;
	for	(i = 0;	i < checkStr.length; i++)
	{
		ch = checkStr.charAt(i);
		if ((ch == "/") || (ch == "^") || (ch == "$") || (ch == "#") || (ch == "§") || (ch == "*") || (ch == "?") || (ch == "%") || (ch == "&")){
			error = true;
		} else {
			if (ch == "@"){
				emailAt	= true;
			}
			if (ch == "."){
				emailPeriod	= true;
			}
		}
	}
	if (emailAt && emailPeriod)
		return true;
	return false;
}

function WriteError( input_name, error ) {
				var div_id = 'error_' + input_name;
				var count = 0;
				if( obj = document.getElementById( div_id ) ) {
					if( error.length != 0 ) {
						obj.innerHTML = error;
					}
					if( obj2 = document.getElementsByName( input_name )[0] ) {
						if( obj2.type != 'checkbox' && obj2.type != 'radio' && obj2.type != 'submit' ) {
							obj2.style.background = '#d7dde2';
							count++;
						}
					}
				} else {
					alert( error + " @ " + input_name );
				}
			}
var feedsHeight = 0;
			$(document).ready( function() {
				feedsHeight = $('#feeds').height();
				$('.sbtContainer').height( feedsHeight );
				$('input').focus( function() { if( $(this).css('background-color') == '#d7dde2' || $(this).css('background-color') == 'rgb(215, 221, 226)' ) { $(this).css('background-color', '#fff'); }  } );
				$('textarea').focus( function() { if( $(this).css('background-color') == '#d7dde2' || $(this).css('background-color') == 'rgb(215, 221, 226)' ) { $(this).css('background-color', '#fff'); }  } );
				
					$(window).resize( function( ) {
						if( $('.testplayer').size() > 0 ) {
							ytPlayerSize();
						}
					});
			});

			function loadFeed( id ) {
				$.ajax({
					type: "POST",
					url: "getFeed.php",
					dataType: "json",
					data: "id="+id,
					success: function( ret ){
						if( ret == '-1' ) {
							alert( 'error occured' );
							return;
						}
						ytPlayer( ret );
					}
				});
			}

function relocate( url ) {
	location.href = url;

}

function ytPlayer( data ) {
	$('#sbtFeed h2').html( data.title );
	/* <div class="close" onclick="javascript: $(\'.testplayer\').remove();">סגור</div> */
	var picHTML = '';
	if( data.picture != '' ) {
		picHTML = '<img src="pictures/careas/'+data.picture+'" alt="" class="boxIm" />';
	}
	var backHTML = '<div class="closef" onclick="javascript: closeFeed();">חזור</div><br class="clear"/>';
	$('#sbtFeed .feed').html( picHTML + data.content + backHTML );
	var sbfh = $('#sbtFeed').height();
	$('.sbtContainer').animate( { height: sbfh+'px' }, 500 );
	$('#feeds').animate( { right: '-212px' }, 500 ); $('#sbtFeed').animate( { right: '0px' }, 500 ); 
	/*$('body').append('<div class="testplayer"><center><div class="tplayer"><div class="title">'+data.title+'<div class="close" onclick="javascript: $(\'.testplayer\').remove();$(\'object:eq(0)\').show();">סגור</div></div><br class="clear" /><div id="ytapiplayer">'+picHTML+data.content+'</div></div></center></div>');
	ytPlayerSize();*/
}

function closeFeed( ) {
	$('.sbtContainer').animate( { height: feedsHeight+'px' }, 500 );
	$('#sbtFeed').animate( { right: '202px' }, 500 ); 
	$('#feeds').animate( { right: '0px' }, 500 ); 
}

function ytPlayerSize() {
	if( $(window).height() > $('body').height() ) {
		$('.testplayer').height( $(window).height() );
		var x = ($(window).height() / 2) - ($('.tplayer').height() / 2);
	} else {
		$('.testplayer').height( $('body').height() );
		var x = ($('body').height() / 2) - ($('.tplayer').height() / 2);
	}
	
	if( $(window).width() > $('#base').width() )
		$('.testplayer').width( $(window).width() );
	else $('.testplayer').width( $('#base').width() );
	
	$('.tplayer').css('margin-top', x+'px');
}

