
$(document).ready(function(){

	$('a.show-popup').simpleLightbox({
		lightboxContentBlock: '.popup',
		faderOpacity: 0.6,
		faderBackground: '#000000',
		closeLink:'a.close',
		href:true,
		onClick: null
  });

  $('.sec_h4 .sec_h4l_ca').jCarouselLite({
      vertical: true,
//      btnPrev: ".prevy",
//      btnNext: ".nexty",
      btnPrev: ".nexty",
      btnNext: ".prevy",
      circular: true,
      visible: 5,
      scroll: 1
  });
  $('.sec_h4 .sec_h4r_ca').jCarouselLite({
      vertical: true,
//      btnPrev: ".prevx",
//      btnNext: ".nextx",
      btnPrev: ".nextx",
      btnNext: ".prevx",
      circular: true,
      visible: 3,
      scroll: 1
  });
  $('.r_c_sec_3 .carousel').jCarouselLite({
      vertical: true,
//      btnPrev: ".prevx",
//      btnNext: ".nextx",
      btnPrev: ".nextx",
      btnNext: ".prevx",
      circular: true,
      visible: 3,
      scroll: 1
  });
  
  if($('.sec_h5 .carousel li').length>0)
  {
      $('.sec_h5 .carousel').jCarouselLite({
          vertical: false,
          auto:8000,
          btnPrev: ".prevz",
          btnNext: ".nextz",
          circular: true,
          visible: 3,
          scroll: 3
      });
  }
  
  $('.m_section .carousel').jCarouselLite({
      vertical: false,
//      btnPrev: ".prevz",
//      btnNext: ".nextz",
      btnPrev: ".nextz",
      btnNext: ".prevz",
      circular: true,
      visible: 3,
      scroll: 3
  });
  $('.r_c_sec_2 .carousel').jCarouselLite({
      vertical: true,
//      btnPrev: ".prevzz",
//      btnNext: ".nextzz",
      btnPrev: ".nextzz",
      btnNext: ".prevzz",
      circular: true,
      visible: 4,
      scroll: 1
  });
  $('.slide_t1 .lp .more').bind('click', function () {
    $(this).hide();
    $('.slide_t1 .lp .moreopen').show();
    return false;
  });
  $('.slide_t1 .lp .moreopen h4').bind('click', function () {
    $(this).parent().hide();
    $('.slide_t1 .lp .more').show();
    return false;
  });
  $('#slideshowPop .newGalToggle').bind('click', function () {
    $(this).parent().next().toggle();
    return false;
  });
  $('#slideshowPop .show_a2g').bind('click', function () {
    $(this).next().toggle();
    return false;
  });
  $('#slideshowPop .add2gal h4 span').bind('click', function () {
    $(this).parents('.add2gal').hide();
    return false;
  });
  $('.pull-up').toggle(
    function () {
      $('#footer-slide').css('top','-490px');
      $('#footer').css('overflow','visible');
    },
    function () {
      $('#footer-slide').css('top','0px');
      $('#footer').css('overflow','hidden');
    }
  );
});


$(document).ready(function(){
		//slideGal5($('.r_c_sec_cc'));
		slideGal000($('.r_c_sec_cc'));
});

//By Mahongtao Begin
function slideGal000(gal_holders){
	gal_holders.each(function(){
	
		var gal_hold = $(this);
		var list_hold = gal_hold.find('.carousel > ul');
		var list_hold_list = gal_hold.find('.carousel > ul li');
		var btn_prev = gal_hold.find('.nextyy');
		var btn_next = gal_hold.find('.prevyy');
		var activeIndex=0;
		
		
		list_hold_list.eq(activeIndex).find('.more-box').show();
		
		if(list_hold_list.length > 1)
		{
			btn_next.click(function()
			{
			    var mm=-80;
			    
				activeIndex++;
				
				if(activeIndex==list_hold_list.length) {activeIndex=0;mm=0;}

				list_hold_list.find('.more-box').slideUp(500);
				
				list_hold_list.eq(activeIndex).find('.more-box').slideDown(500);
				
				
				for(i=0;i<activeIndex;i++)
				{
				    mm+=list_hold_list.eq(i).outerHeight();
				}
				
				list_hold.animate({marginTop: -mm }, 500);
						
				return false;
			});

			btn_prev.click(function(){
				
				var mm=-0;
				
				activeIndex--;
				
				if(activeIndex==-1) {activeIndex=list_hold_list.length-1;mm=-80;}

				list_hold_list.find('.more-box').slideUp();
				
				list_hold_list.eq(activeIndex).find('.more-box').slideDown(500);
				
				for(i=0;i<activeIndex;i++)
				{
				    mm+=list_hold_list.eq(i).outerHeight(500);
				}
				
				list_hold.animate({marginTop: -mm }, 500);
						
				return false;
			});
		}
		else
		{
			btn_prev.click(function(){ return false;});
			btn_next.click(function(){ return false;});
		}
	});
}

//By Mahongtao End

/*--- function slideGal5 ---*/
function slideGal5(gal_holders){
	gal_holders.each(function(){
		var gal_hold = $(this);
		var list_hold = gal_hold.find('.carousel > ul');
		var btn_prev = gal_hold.find('.nextyy');
		var btn_next = gal_hold.find('.prevyy');
		var _list = list_hold.children();
		var _a = 0;
		var _m = 0;
		if(_list.length > 1) {
			list_hold.append(list_hold.children().clone());
			_list.eq(_a).find('.more-box').show();
			var t_h;
			btn_next.click(function(){
				if(!list_hold.is(':animated')){
					if(_a < _list.length - 1){

						_list.eq(_a).find('.more-box').each(function(){

						}).slideUp(500);
						
						_m += 88;
						list_hold.animate({marginTop: -_m }, 500);
						_list.eq(_a+1).find('.more-box').slideDown(500);
						_a++;
					}
					else{

						_list.eq(_a).find('.more-box').each(function(){

						}).slideUp(500);
						_m += 88;
						list_hold.animate({marginTop: -_m}, 500);
						list_hold.children().eq(_list.length).find('.more-box').slideDown(500, function(){
							_a = 0;
							_m = 0;
							_list.eq(_a).find('.more-box').show();
							_list.eq(_a).css('margin-left', "150");
							list_hold.children().eq(_list.length).find('.more-box').hide();
						});
					}
				}
				return false;
			});
			var _f2 = false;
			btn_prev.click(function(){
				if(!list_hold.is(':animated')){
					if(_a > 0){
						t_h = _list.eq(_a).outerHeight();
						_list.eq(_a).find('.more-box').each(function(){
							t_h -= $(this).outerHeight();
						}).slideUp(500);
						_m -= 88;
						list_hold.animate({marginTop: -_m}, 500);
						_list.eq(_a - 1).find('.more-box').slideDown(500);
						_a--;
					}
					else{
						_list.eq(_a).find('.more-box').hide();
						_list.each(function(){ _m += $(this).outerHeight();});
						list_hold.css('margin-top', -_m);
						_a = _list.length - 1;
						_m -= 88;
						list_hold.children().eq(_list.length).find('.more-box').show().slideUp(500);
						list_hold.animate({marginTop: -_m}, 500);
						_list.eq(_a).find('.more-box').slideDown(500);
					}

				}

				return false;
			});
		}
		else{
			_list.eq(_a).find('.more-box').show();
			btn_prev.click(function(){ return false;});
			btn_next.click(function(){ return false;});
		}
	});
}


function writeCookie(name, value, days)
{
    if (days)
    {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
    }
    else var expires = "";
    document.cookie = name + "=" + value + expires + "; path=/; domain=papercitymag.com";
}

function readCookie(name)
{
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++)
    {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
    return null;
}

function clearCookie(name)
{
    writeCookie(name, "", -1);
}

function init(list_hold) {
	//initialize inactive item and inactive text
	list_hold.find("li > .item").css("width", "175px");	
	list_hold.find("li > .item > .text").css("width", "163px");	
	//initialize inactive imgs 
	list_hold.find("li > .item > .imgs > img").css("width", "0px");
		
	//initialize active item and active text
	list_hold.find(".active > .item").css("width", "380px");
	list_hold.find(".active > .item > .text").css("width", "205px");	
	//initialize active imgs
	list_hold.find(".active > .item > .imgs > img").css("width", "160px");	
}

function resetAttr(list_hold) {
	var _slip_speed = 500;
	//initialize inactive item and inactive text
	list_hold.find("li > .item").animate({width:175}, _slip_speed);	
	list_hold.find("li > .item > .text").animate({width:163}, _slip_speed);
	//initialize inactive imgs 
	list_hold.find("li > .item > .imgs > img").animate({width:0}, _slip_speed);
		
	//initialize active item and active text
	list_hold.find(".active > .item").animate({width:380}, _slip_speed);
	list_hold.find(".active > .item > .text").animate({width:205}, _slip_speed);
	//initialize active imgs
	list_hold.find(".active > .item > .imgs > img").animate({width:160}, _slip_speed);
}

function slideGal6(gal_holders){
	gal_holders.each(function(){
		var gal_hold = $(this);
		var list_hold = gal_hold.find('.l_o_p_c > ul');
		var btn_prev = gal_hold.find('.btnNext');
		var btn_next = gal_hold.find('.btnPrev');
		var _list = list_hold.children();
		var _a = 0;
		var _m = 0;
		var _init_length = _list.length;
		var _animate_duration = 800;
		
		init(list_hold);
		
		var _width = _list.eq(_list.length - 1).outerWidth();
						
		if(_list.length > 1) {
			btn_next.click(function(){
				if(!list_hold.is(':animated')){
					if (_a > 0) {
						_m += _width;
						_list.eq(_a).removeClass("active");
						_list.eq(_a-1).addClass("active");
						resetAttr(list_hold);
						list_hold.animate({marginLeft: _m}, _animate_duration);
						_a--;
						$('#googleAdH').attr('src','/GoogleAD.htm?t='+(new Date()).getTime());
					} else {
						_m=0;
						_a=0;
						list_hold.css('margin-left', 0);
					}
				}
				return false;
			});
			btn_prev.click(function(){
				if(!list_hold.is(':animated')){
					if (_a < _init_length) {
						_list.eq(_a).removeClass("active");
						_m -= _width;
						_a++;
						_list.eq(_a).addClass("active");
						resetAttr(list_hold);
						list_hold.animate({marginLeft: _m}, _animate_duration);
						
						var _tmp_li = document.createElement("li");
						_tmp_li.innerHTML = _list.eq(_a-1)[0].innerHTML;
						list_hold.append(_tmp_li);
						_list = list_hold.children();
						init(list_hold);
						$('#googleAdH').attr('src','/GoogleAD.htm?t='+(new Date()).getTime());
					}
				}
				return false;
			});
		}
		else{
			btn_prev.click(function(){ return false;});
			btn_next.click(function(){ return false;});
		}
	});
}



$(document).ready(function(){
		slideGal6($('.l_o_p'));
});
