$(document).ready(function() {
	$('#vote_submit').click(function(){
		var user_id=$('#poll_form #poll_user_id').val();
		var answer_id=$('.poll_answer:checked').val();
		var url='/ajax/vote.php?user_id='+user_id+'&voted_for='+answer_id;
		//alert(url);
		if(!answer_id){
		
		}else{
			$('#vote_b').load(url);
		}
		
	});
	
	$('div#list').load('/ajax/filelist.php');
	
	$('a.infolink').click(function(){
		//$('#assets_addinfo').html($(this).attr('alt'));
		$('#assets_addinfo').load('/ajax/asset_info.php?id='+$(this).attr('alt'));
	});
	
	$('#file_upload').uploadify({
		'uploader' : '/js/upl/uploadify.swf',
		'script' : '/video_uploader.php',
		'cancelImg' : '/js/upl/cancel.png',
		'folder' : '/uploads',
		'auto' : true,
		'buttonText' : 'Load File',
		'fileExt' : '*.avi;*.mov;*.flv',
		'multi' : true,
		'onComplete' : function(event, ID, fileObj, response, data) {
			$('div#msg').html(response);
			$('div#list').hide('slow');
			$('div#list').load('/ajax/filelist.php');
			$('div#list').show('slow');
			//alert("Загрузка завершена "+response);
		},
		'onerror' : function (event,ID,fileObj,errorObj) {
			alert(errorObj.type + ' Ошибка: ' + errorObj.info);
		}
	});

	
	$('a.make_week_video').live('click',function(){
		var url='/ajax/week_video.php?act=make&id='+$(this).attr('alt');
		$('div#list').html('<img src="/img/loader.gif" />');
		$.ajax({
			url: url,             // указываем URL и
			dataType : "json",                     // тип загружаемых данных
			success: function (data, textStatus) { // вешаем свой обработчик на функцию success
					$('div#list').hide();
					$('div#list').load('/ajax/filelist.php',function(){
						$('div#list').show('slow');
					});
					
				}
		});
	});
		//$('div#list').load(url,function(){
		
		//});
		
		
		//alert(url);
	
	
	$('a.make_not_week_video').live('click',function(){
		var url='/ajax/week_video.php?act=unmake&id='+$(this).attr('alt');
		$('div#list').html('<img src="/img/loader.gif" />');
		$.ajax({
			url: url,             // указываем URL и
			dataType : "json",                     // тип загружаемых данных
			success: function (data, textStatus) { // вешаем свой обработчик на функцию success
					$('div#list').hide();
					$('div#list').load('/ajax/filelist.php',function(){
						$('div#list').show('slow');
					});
					
				}
		});
	});
	
	$('a.photo_detailed_info').click(function(){
		var e_w=$(this).next('div').width();
		var e_h=$(this).next('div').height();
		var left=$(this).offset().left+'px';
		var top=$(this).offset().top+'px';
		
		$(this).next('div').css({'top':top,'left':left,'position':'absolute','background-color':'White','border':'1px solid Silver','color':'Gray', 'z-index':'100','padding':'10px'}).toggle();
	});
	
	
	
});
 


$(document).ready(function() {

$('ul.tabs li').css('cursor', 'pointer');

$('ul.tabs.tabs1 li').click(function(){
	var thisClass = this.className.slice(0,2);
	$('div.t1').hide();
	$('div.t2').hide();
	$('div.t3').hide();
	$('div.t4').hide();
	$('div.' + thisClass).show();
	$('ul.tabs.tabs1 li').removeClass('tab-current');
	$(this).addClass('tab-current');
	});
});

$(document).ready(function() {

	$('a.open_make_odd').click(function(){
		$(this).next('div').toggle();
	});
	
	$('a.make_odd').click(function(){
		var parent=$(this).parent();
		var game_id=parent.attr('id');
		
		var score1st=$('div#'+game_id+' input[name=score1st]').val();
		var score2nd=$('div#'+game_id+' input[name=score2nd]').val();
		var userid=$('div#'+game_id+' input[name=userid]').val();
		var url='/ajax/saveodd.php?gameid='+game_id+'&score1st='+score1st+'&score2nd='+score2nd+'&userid='+userid;
		//alert(url);
		$.ajax({
			url: url,
			async: true,
			success:function(html){
				if(html=='Added'){
					var newtext='<input name="score1st" type="text" disabled="disabled" size="3" value="'+score1st+'" />&nbsp;:&nbsp;<input name="score2nd" type="text" disabled="disabled" size="3" value="'+score2nd+'" /> Изменить ставку можно в разделе <a href="/profile/my_odds">Мои прогнозы</a></div>';
					$('div#'+game_id).html(newtext);
				}
				
		}
		});
	});
	
	$('a.save_edit_odd').live('click',function(){
		var odd_id=$(this).parent().children('input[name=odd_id]').val();
		var score1=$(this).parent().children('input[name=score1]').val();
		var score2=$(this).parent().children('input[name=score2]').val();
		var game_id=$(this).parent().children('input[name=game_id]').val();
		var url='/ajax/editodd.php?odd_id='+odd_id+'&score1st='+score1+'&score2nd='+score2+'&game_id='+game_id;
		$.ajax({
			url: url,
			async: true,
			success: function () {
						$('#my_odds_list').hide('slow').load('/ajax/loadoddlist.php',function(){$('#my_odds_list').show('slow');})
					}
		});
	});
	
	$('#cart').load('/ajax/cart_content.php');
	
	$('a.update_cart_item').live('click',function(){
		var count=$(this).parents('tr').children('td').children('input[name=count]').val();
		var id=$(this).attr('alt');
		var url='/ajax/update_item.php?id='+id+'&count='+count;
		$.ajax({
			url: url,
			async: true,
			success:function(){
				window.location.replace('/cart/');
			}
		});
	});
	
	$('#confirm_order').live('click', function(){
		var remark=$('#confirm_remark').val();
		var url='/ajax/confirm_order.php?confirm_remark='+remark;
		//alert(url);
		$.ajax({
			url: '/ajax/confirm_order.php?confirm_remark='+remark,
			async: false,
			success:function(){
				window.location.replace('/cart/');
			}
		});
		jAlert('Заказ принят', '');
		
	});
	
	$('a.show_order').live('click',function(){
		$(this).parents('tr').next('tr').toggle();
	});
	
	$('#want_to_login').click(function() {
		$.blockUI({ css: { 
            border: 'none', 
            padding: '15px', 
            backgroundColor: 'none',
            cursor: 'pointer',
        }, 
        message: $('#loginForm')
        }); 		
    });
	$('#want_to_register').click(function() {
		$.blockUI({ css: { 
            border: 'none', 
            padding: '15px', 
            backgroundColor: 'none',
            cursor: 'pointer',
        }, 
        message: $('#registerForm')
        }); 		
    });

	$('#want_to_beta').click(function() {
		$.blockUI({ css: { 
            border: 'none', 
            padding: '15px', 
            backgroundColor: 'none',
            cursor: 'pointer',
        }, 
        message: $('#betaForm')
        }); 		
    });
	
	$('#want_to_beta1').click(function() {
		$.blockUI({ css: { 
            border: 'none', 
            padding: '15px', 
            backgroundColor: 'none',
            cursor: 'pointer',
        }, 
        message: $('#betaForm')
        }); 		
    });
	
	
	$('#show_video').click(function() {
		$.blockUI({ css: { 
            border: 'none', 
            padding: '15px', 
            backgroundColor: 'none',
            cursor: 'pointer',
        }, 
        message: $('#player')
        }); 		
    });
	$('#show_video1').click(function() {
		$.blockUI({ css: { 
            border: 'none', 
            padding: '15px', 
            backgroundColor: 'none',
            cursor: 'pointer',
        }, 
        message: $('#player')
        }); 		
    });
	
	
	
	$('#want_to_login_need').click(function() {
		$.blockUI({ css: { 
            border: 'none', 
            padding: '15px', 
            backgroundColor: 'none',
            cursor: 'pointer',
        }, 
        message: $('#loginForm')
        }); 		
    });
	
	$('#want_to_register_need').click(function() {
		$.blockUI({ css: { 
            border: 'none', 
            padding: '15px', 
            backgroundColor: 'none',
            cursor: 'pointer',
        }, 
        message: $('#registerForm')
        }); 		
    });
	
	
	$('#close_img').click(function() {
		$.unblockUI({ 
			onUnblock: function(){ } 
		}); 	
    });

	$('#close_text').click(function() {
		$.unblockUI({ 
			onUnblock: function(){ } 
		}); 	
    });
	
	$('#close_img1').click(function() {
		$.unblockUI({ 
			onUnblock: function(){ } 
		}); 	
    });

	$('#close_text1').click(function() {
		$.unblockUI({ 
			onUnblock: function(){ } 
		}); 	
    });
	
	$('#close_img2').click(function() {
		$.unblockUI({ 
			onUnblock: function(){ } 
		}); 	
    });

	$('#close_text2').click(function() {
		$.unblockUI({ 
			onUnblock: function(){ } 
		}); 	
    });

	$('#close_img3').click(function() {
		$.unblockUI({ 
			onUnblock: function(){ } 
		}); 	
    });

	$('#close_text3').click(function() {
		$.unblockUI({ 
			onUnblock: function(){ } 
		}); 	
    });
	
	
	
	
});

function add_to_cart ( product_id ) {
	
	var url = '/js/jserver.php?action=add_to_cart&product_id='+ product_id;
	$.ajax({
		url: url,
		async: true,
		success:function(){
			$('#cart').load('/ajax/cart_content.php');
		}
	});
	/*
	jQuery.getJSON(url, {}, function(json){
        jQuery('#cart').html('');
        jQuery('#cart').append(json.response.body);
		jQuery('#cart').fadeIn('slow', function() {
            // Animation complete.
        });
     */
		jAlert('Товар добавлен в корзину<br><a href="/cart/">Оформить заказ</a>', 'Вы добавили товар в корзину');
   
}

function clear_cart(){
	$.ajax({
		url: '/ajax/clear_cart.php',
		async: true,
		success:function(){
			$('#cart').load('/ajax/cart_content.php');
		}
	});
}

function deleteItem(id){
	$.ajax({
		url: '/ajax/delete_item.php?id='+id,
		async: true,
		success:function(){
			window.location.replace('/cart/');
		}
	});
}

function confirm_order(){
	
}


//стираем из поля слова "поиск" и т.д.
function clearField(field, value) {
	var field = document.getElementById(field);

	if (field.value == value)
		field.value = "";
}

//заполняем поле словом "поиск"
function fillField(field, value) {
	var field = document.getElementById(field);

	if (field.value == "")
		field.value = value;
}

