$(document).ready(function(){
	//Pastebejai kaida
	$('#closeCloud').bind('click',function(){
		setCookie('cloudOff','ok',null);
		$(this).parent().hide('slow');
	});
	$('#bugsCloud span').bind('click',function(){
		popCloudFormWindow();
	});
	$('#UserSendCloudMailForm div.submit input').live('click',function(){
		$('p.error').remove();
		var name = $('#UserSendCloudMailForm input[name=name]');
        var email = $('#UserSendCloudMailForm input[name=email]');        var url = $('#UserSendCloudMailForm input[name=url]');
        var comment = $('#UserSendCloudMailForm textarea[name=text]');
		
		var data = 'name=' + name.val() + '&email=' + email.val()+'&text='  + encodeURIComponent(comment.val())+'&url=' + url.val();
		if(comment.val().length == 0 ){
			comment.parent().append('<p class="error">Užpildykite teksto laukelį</p>');
			return false;
		}else{
			$.ajax({
				url: root+'users/send_cloud_mail', 
				type: 'post',
				data: data,
				beforeSend: function() {
					$('.blockUI form').remove();
					$('.blockUI #preloader').show();
				},		
				success: function(data) {
					$('#preloader').html(data);
				}
			});
			return false;
		}
	});
	
	
   $('.round').append('<img src="'+root+'/css/tw.png" alt="" style="position: absolute; top: 0; left: 0;" />');
   $('.round').append('<img src="'+root+'/css/te.png" alt="" style="position: absolute; right: 0; top:0;" />');
   $('.round').append('<img src="'+root+'/css/be.png" alt="" style="position: absolute; right: 0; bottom: 0;" />');
   $('.round').append('<img src="'+root+'/css/bw.png" alt="" style="position: absolute; left: 0; bottom: 0;" />');
	$('.search').bind('click',function(){
		$('#hiddenPart').children('#hiddenContainer').toggle();;
	});
	/*$('#content,.middle').bind('mouseover',function(){
		$('#hiddenPart').children('#hiddenContainer').hide('slow');
	});*/
	$('#AdvertismentType').change(function () {
		$('img#preloader').show();
	});
	$('#main_category_search').change(function () {
		$('img#preloader2').show();
	});
	
	$('div#leftPartP').mousemove(function(e){
		var contPos = $(this).scrollTop();
		var dif = e.pageY - $(this).offset().top;
		if (dif < ($('div#leftPartP').height() - $('ul#examples').height())) {
			$('ul#examples').css('top', (dif)+ 'px');
		}
   });
   
   $('#AdvertismentShortBio').bind('click',function(){
   	if($(this).attr('checked') == true){
		$('#AdvertismentName,#AdvertismentYear,#AdvertismentHeight').attr('disabled','disabled');
		$('#AdvertismentName').removeClass('validate[required,custom[onlyLetter]]');
	}else{
		$('#AdvertismentName').addClass('validate[required,custom[onlyLetter]]');
		$('#AdvertismentName,#AdvertismentYear,#AdvertismentHeight').removeAttr('disabled');
	}
   });
   $('#AdvertismentShortContacts').bind('click',function(){
   	if($(this).attr('checked') == true){
		$('#AdvertismentEmail,#AdvertismentPhone,#AdvertismentCity').attr('disabled','disabled');
	}else{
		$('#AdvertismentEmail,#AdvertismentPhone,#AdvertismentCity').removeAttr('disabled');
	}
   });
	a = $('#interest1').offset();
	
	$('div.submit').after('<br class="clear" />');
	
	$('form#PhoneRaiseForm div.cancel button').live('click',function(){
		var id = $(this).parent().parent().children('input#PhoneId').val();
		$.post(root+'advertisments/checkAdvCanceling/'+id,function(data){
			$.unblockUI({});
			window.location = root;
			})
		return false;
	});
	
	
});

function setCookie(c_name,value,expiredays){
		var exdate=new Date();
		exdate.setDate(exdate.getDate()+expiredays);
		document.cookie=c_name+ "=" +escape(value)+
		((expiredays==null) ? "" : ";expires="+exdate.toGMTString())+";path=/";
	}
	
function popCloudFormWindow(){
	$.post(root+'users/show_cloud_form',{ url: curr_url}, function(data) {
	   	$.blockUI({ message: data+' <br /><font class="closePopupButton" onclick="$.unblockUI({});" face="Arial" style="color:#149b0d;"></font>',
							css: { width: '540px', padding: '0px'} 
					});
			$('.blockUI.blockMsg').append(
			 	'<img src="'+root+'img/round_popup_bottom.png" style="position: absolute; bottom: -8px; left: 0; "/>'+
			 	'<img src="'+root+'img/round_popup_top.png" style="position: absolute; top: -8px; left: 0; "/>' 
			);
			$('.blockUI.blockMsg').css('filter','none');
	 });
	return false;
}
