$(document).ready(function() {
  $("div.common").mouseover(function ()
  {
    $(this).addClass("mouse_hover");
  });

  $("div.common").mouseout(function ()
  {
    $(this).removeClass("mouse_hover");
  });
  
    $("#rss").hover(function ()
  {
    $(this).find('img').attr("src","images/rss_on.png"); 
  },function ()
  {
    $(this).find('img').attr("src","images/rss_off.png"); 
  });
  
  $("#podcast").hover(function ()
  {
    $(this).find('img').attr("src","images/podcast_on.png"); 
  },function ()
  {
    $(this).find('img').attr("src","images/podcast_off.png"); 
  });
  
  $("#twitter").hover(function ()
  {
    $(this).find('img').attr("src","images/twitter_on.png"); 
  },function ()
  {
    $(this).find('img').attr("src","images/twitter_off.png"); 
  });
  
  $("#facebook").hover(function ()
  {
    $(this).find('img').attr("src","images/facebook_on.png"); 
  },function ()
  {
    $(this).find('img').attr("src","images/facebook_off.png"); 
  });
  
	currr_page = $('input[name=curr_page]').val();
	maxx_page = $('input[name=max_page]').val();
	if (currr_page <= 1) {
		$('#arr_scroll_up').hide();
	}
	if(currr_page == maxx_page) {
		$('#arr_scroll_down').hide();
	}

	$('#img_video3').click( function ()
	{
		$('#img_video').show();
		$('#img_video2').hide();
	})
	$('.giveto a').hover(change_img,def_img);
	$('.event a').hover(change_event,def_event);
	
	
  $("div.common").trigger('mouseover');
	$("div.common").trigger('mouseout');
	
	img_path=$('#image_path').text();
	var but_img=new Image();
	but_img.src=img_path;	
	$('.giveto_button_inner').css('background-image','url('+img_path+')');
	
	img_path2=$('#image_path2').text();
	var but_img2=new Image();
	but_img2.src=img_path;	
	$('.giveto_button_inner2').css('background-image','url('+img_path2+')');
});

function scroll_up()
{

	mheight = 290;
	
	currr_page = $('input[name=curr_page]').val();

	if ((parseInt(currr_page) - 1) <= 1) {
		$('#arr_scroll_up').hide();
	}
	if (currr_page <= 1) {
		return false;
	}
	if ((parseInt(currr_page) + 1) != maxx_page) {
		$('#arr_scroll_down').show();
	}
	$('input[name=curr_page]').val(parseInt(currr_page)-1);
	etop = $('div.podcasts_inner').css('top');
	etop = etop.replace('px', '');
	etop = parseInt(etop) + mheight;
	$('div.podcasts_inner').animate({'top': etop+'px'}, 'slow');
	return false;
}

function scroll_down()
{

	mheight = 290;

	ttype = $('input[name=type]').val();
	loadedd_page = $('input[name=loaded_page]').val();
	maxx_page = $('input[name=max_page]').val();
	currr_page = $('input[name=curr_page]').val();
	
	if ((parseInt(currr_page) + 1) == maxx_page) {
		$('#arr_scroll_down').hide();
	}
	
	/*if (currr_page == maxx_page) {
		$('#arr_scroll').hide();
		return false;
	}*/
	if((parseInt(currr_page)) >= 1) {
		$('#arr_scroll_up').show();
	}
	
	new_page = parseInt(currr_page) + 1;
	if (parseInt(loadedd_page) >= new_page) {
		$('input[name=curr_page]').val(new_page);
		etop = $('div.podcasts_inner').css('top');
		etop = etop.replace('px', '');
	
		etop = parseInt(etop) - mheight;
		$('div.podcasts_inner').animate({'top': etop+'px'}, 'slow');
		return false;
	} else {
	
	$.ajax({ 
		type:"POST",
		url:"ajax_view.php",
		data:'type='+ttype+'&page='+new_page,
		success: function(htm) {
			$('div.podcasts_inner').append(htm);
			$('input[name=loaded_page]').val(new_page);
			$('input[name=curr_page]').val(new_page);
			etop = $('div.podcasts_inner').css('top');
			etop = etop.replace('px', '');
	
			etop = parseInt(etop) - mheight;
			$('div.podcasts_inner').animate({'top': etop+'px'}, 'slow');
		}
	});
	}
	return false;
}

function change_img()
{
	$(this).find('img').attr('src','images/give_to_pihop_hover.png');
}

function def_img()
{
		$(this).find('img').attr('src','images/give_to_pihop.png');
}

function change_event()
{
	$(this).find('img').attr('src','images/events_hover.png');
}

function def_event()
{
		$(this).find('img').attr('src','images/events.png');
}

function show_linka()
{	
	$('.active').hide();
	$('.active').removeClass('active');
	$(this).next('a').fadeIn(250);
	$(this).next('a').addClass('active');
}
function hide_linka()
{
}
