﻿var suiji80to100 = 80+Math.ceil(Math.random()*20);
var suiji3to13 = 3+Math.ceil(Math.random()*10);
var paiming = suiji3to13 +Math.ceil((300000*15*suiji80to100) /(100*readedItemsCount));
var styleIndex = 0; 
var readedItemsCount = 15;
var jianjiezhiguanMoshiIndex = 0; 
var tickCount  = 0;
var pageCount = 0 ;
var tishiCount =  5;
var daodi=0;
var bixufanye=0;
var fanyehouDiyici=0;
var maxPerPage=61;
var RefreshPage1 = function() {$.scrollTo('+=1px', 10);
setTimeout(RefreshPage2,3000);  };
var RefreshPage2 = function() {$.scrollTo('-=1px', 10);};
setTimeout(RefreshPage1, 3000); 


var addFav = function() { var ctrl = (navigator.userAgent.toLowerCase()).indexOf('mac') != -1 ? 'Command/Cmd':'Ctrl';
		var myloc = "http://www.2shishang.cn";
		var mytitle = "时尚之家，2shishang.cn";
		if(document.all)
		{
			window.external.addFavorite(myloc,mytitle);
		}
		else if(window.sidebar)
		{ 
			window.sidebar.addPanel(mytitle,myloc);
		}
		else{
			//top.location = myloc;
			alert('请用Ctrl+D进行添加');
		}}

var RefreshTitle = function() { 
var readInfo = "";
if(tickCount  %2==0)
    readInfo += "刚翻了【"+readedItemsCount +"】件宝贝，在今日翻翻排行榜里排名【"+paiming+"位】" ;
else
    readInfo += "刚翻了  "+readedItemsCount +"  件宝贝，在今日翻翻排行榜里排名【"+paiming+"位】" ;
tickCount ++;
document.title=readInfo; 

setTimeout(RefreshTitle, 1000); 
};
setTimeout(RefreshTitle, 1000); 
var ie = -[1,];
$(function(){
$('#container  .controlFullScr').mouseover(function(){
    if(styleIndex ==0){$('#container .controlFullScr img').css("border","1px solid grey");}
}).mouseout(function(){
    if(styleIndex ==0){$('#container .controlFullScr img').css("border","0px solid grey");}
});

$('#container .controlMofaScr').mouseover(function(){
    if(styleIndex ==1){$('#container .controlMofaScr img').css("border","1px solid pink");}
}).mouseout(function(){
    if(styleIndex ==1){$('#container .controlMofaScr img').css("border","0px solid pink");}
});

//判断所属风格
if(styleIndex ==0)
{
   $('#container .controlMofaScr img').css("border","3px solid  pink");
}
else if(styleIndex ==1)
{
   $('#container .controlFullScr img').css("border","3px solid grey");
}
	
});


$(document).ready(function() {
  $(".side-item img").attr("title", function() { return this.alt });
var ie = -[1,];
if(ie)
{
    $(".side-item img").aToolTip();
      $(".goodimg a img").aToolTip();
}
else
{
        $(".goodtitle").animate({
                height: 20
            });
	if(!!window.ActiveXObject&&!window.XMLHttpRequest)
	{
		$("#arrow").css("display","none");$('#container').css("margin-left","80");
		$(".item").css("border","0px solid #D8D8D8;");
	}
}
    $("#arrow").css("position","fixed");    $("#arrow").css("right","0px");    $("#arrow").css("width","auto");    setTimeout("$.scrollTo('+=1px', 10);",2000);
    
    $("#btnbottom").click(function() {
        $.scrollTo('+=550px', 400);
    });
    $("#btntop").click(function() {
        $.scrollTo('0', 400);
    });
             $(".closebar").click(function() {

                $(this).animate({

                    bottom: '0px'

                },

                400,

                function() {

                    $(this).css("display", "none");

                    $(".openbar").css("bottom", "0").css("display", "block");

                });



                $("#taobao_bar").slideUp("normal",

                function() {

                    //关闭结束

                });

            });



            $(".openbar").click(function() {

                $(this).animate({

                    bottom: '170px'

                },

                400,

                function() {

                    $(this).css("display", "none");

                    $(".closebar").css("bottom", "170px").css("display", "block");

                });

                $("#taobao_bar").slideDown("normal",

                function() {

		$("#taobao_bar").css("height", "170");

                    //打开结束

                });

            });
});


$('.jianjieStyle').live('click', function () {jianjiezhiguanMoshiIndex =1;$(".goodinfo").css("display","none");$(".side-item").css("display","none");$(".goodcomment").css("display","none");$(".morecomment").css("display","none");$(".pictag").css("display","none");$('#container').masonry({columnWidth: 238,itemSelector: '.item',isFitWidth: true,isAnimated: false,animationOptions: {duration: 400, easing: 'linear',queue: false}});$('.jianjieStyle').css("display","none");$('.zhiguanStyle').css("display","block");});
$('.zhiguanStyle').live('click', function () {jianjiezhiguanMoshiIndex =0;$(".goodinfo").css("display","block");$(".side-item").css("display","block");$(".goodcomment").css("display","block");$(".morecomment").css("display","block");$(".pictag").css("display","block");            $('#container').masonry({columnWidth: 238,itemSelector: '.item',isFitWidth: true,isAnimated: false,animationOptions: {duration: 400, easing: 'linear',queue: false}});$('.jianjieStyle').css("display","block");$('.zhiguanStyle').css("display","none");});
$('.fanye').live('click', function () {daodi=0;bixufanye=1;fanyehouDiyici=1; $("#fanye2").css("display","none");pageCount=0;$("#tooltipTishi").hide();$(".essenceInfo").html("");$(".nextPag").html("");$('#container').masonry({columnWidth: 238,itemSelector: '.item',isFitWidth: true,isAnimated: false,animationOptions: {duration: 400, easing: 'linear',queue: false}});$('#heightPage').css("height","500px");$.scrollTo('10px', 1000);});


function ChangeTostyle2() { styleIndex =1;   $('#container .controlMofaScr img').css("border","0px solid  pink");//$('#container .controlFullScr img').css("border","3px solid grey");
    $('.yggintro').css("display","none");
    $('.container_header').css("display","none");
    $('.header').css("display","block");
    $('#bodyContainer').removeClass("container");//$('.goodrank').css("background","#F3F3F3");
    $('#container').masonry({columnWidth: 238,itemSelector: '.item',isFitWidth: true,isAnimated: false,animationOptions: {duration: 10, easing: 'linear',queue: false}});$('.controlbar1').css("display","none"); $('.controlbar2').css("display","block"); //$('body').css("background","#e8e7e3");
    //$('.side-item').css("background","#F3F3F3"); $('.itemshadow').css("display","none");$('.goodinfo').css("color","#76838B");$('.morecomment').css("background-color","#f9f9f9");$(".morecomment a").css("color","#AAA");
    //$('.goodcomment').css("border-top","1px solid #E7E7E7");$('.side-item').css("border-top","1px solid #E7E7E7");$('#arrow').css("display","none");

}

 $('.controlFullScr').live('click', function () {ChangeTostyle2(); $.scrollTo('+=50px', 400);});


function ChangeTostyle1() { styleIndex =0;$('#container .controlMofaScr img').css("border","3px solid pink");$('#container .controlFullScr img').css("border","0px solid grey");
    $('.header').css("display","block");
    $('.yggintro').css("display","block");$('.container_header').css("display","block");$('#bodyContainer').addClass("container"); $('.goodrank').css("background","#FFF9F7");
    $('#container').masonry({columnWidth: 238,itemSelector: '.item',isFitWidth: true,isAnimated: false,animationOptions: {duration: 400, easing: 'linear',queue: false}}); $('.controlbar2').css("display","none");$('.controlbar1').css("display","block"); $('body').css("background","#fef4f2 url(/images/transback.jpg) repeat-x  fixed");
    $('.side-item').css("background","#fff9f7");  $('.itemshadow').css("display","block");$('.goodinfo').css("color","#76838B;");$('.morecomment').css("background-color","#FFF9F7");$(".morecomment a").css("color","#AEB7BB");
    $('.goodcomment').css("border-top","1px solid #fcefef");$('.side-item').css("border-top","1px solid #fcefef");$('#arrow').css("display","block");
    
}
 $('.controlMofaScr').live('click', function () {ChangeTostyle1();});



$(function() {
    var $container = $('#container');
    $container.imagesLoaded(function() {
        $container.masonry({
            columnWidth: 238,
            itemSelector: '.item',
            isFitWidth: true,
            isAnimated: false,
            animationOptions: {
                duration: 0,
                easing: 'linear',
                queue: false
            }
        });
    });
    $container.infinitescroll({
        navSelector: '#page_nav',
        nextSelector: '#page_nav #mopouPagenext',
        itemSelector: '.nextPag',
        loadingImg: '/images/1px.jpg',
        loadingImg: '/images/1px.jpg',
        loadingText: ' ',
        donetext: ' ',
        debug: false,
        errorCallback: function() {
            // fade out the error message after 2 seconds
            $('#infscr-loading').animate({
                opacity: .8
            },
            3000).fadeOut('slow');
            $('#infscr-done').css("display", "block");
            $('#infscr-done').animate({
                opacity: .8
            },
            10000).fadeOut('slow');
        }
    },
    // call masonry as a callback.
    function(newElements) {

pageCount++;
if(pageCount==tishiCount)
{
     tishiCount=tishiCount*2;
     //写入翻页代码
     //document.write('<div class="item"><div class="fanye"> 当前页面信息太多？点击翻页</div></div>');
     $("#tooltipTishi").show();
     setTimeout("$('#tooltipTishi').hide();",5000)
}
var ie = -[1,];
if(ie)
{
    $(".side-item img").aToolTip();  
    $(".goodimg a img").aToolTip();
}
else
{
     $(".goodtitle").animate({
                height: 20
            });
}
            var $newElems = $(newElements);
            // ensure that images load before adding to masonry layout
if(fanyehouDiyici==0)
{
            $newElems.hide();
}
else
{
	fanyehouDiyici=0;
}

            $newElems.imagesLoaded(function() {
            $newElems.show();
	    readedItemsCount =readedItemsCount +15;
if(readedItemsCount>maxPerPage)
{
	if(ie)
	{}
	else
	{
		//到底了
		$("#heightPage").css("height","0");
		daodi=1;
        $("#fanye2").css("display","block");
        maxPerPage+=80;
	}
}
paiming = 3+Math.ceil((300000*15*suiji80to100) /(100*readedItemsCount));
            $container.masonry('appended', $newElems, true);
            if(styleIndex==1)
            {ChangeTostyle2();}
           });
            if(jianjiezhiguanMoshiIndex ==1)
            {
               $(".goodinfo").css("display","none");$(".side-item").css("display","none");$(".goodcomment").css("display","none");$(".morecomment").css("display","none");$(".pictag").css("display","none");$('#container').masonry({columnWidth: 238,itemSelector: '.item',isFitWidth: true,isAnimated: false,animationOptions: {duration: 400, easing: 'linear',queue: false}});$('.jianjieStyle').css("display","none");$('.zhiguanStyle').css("display","block");
            }
});
 
jQuery.fn.outer = function() { 
	    return $($('<div></div>').html(this.clone())).html();
	} 

var readItem1,readItem2,readItem3,readItem4,readItem5;
$(".goodimg").live({
mouseenter: function() {
if(ie)
{          
        $(this).parent().children(".goodrank").animate({height:117});
        $(this).children(".goodtitle").animate({
                height: 20
            });
      if(jianjiezhiguanMoshiIndex ==1)
      {
            $(this).parent().children(".goodinfo").show();
            $(this).parent().children(".side-item").show();
            $(this).parent().children(".goodcomment").show();
            $(this).parent().children(".morecomment").show();
            $(this).parent().children(".pictag").show();

      }
            $(this).parent().css({"z-index":"99"});
}
else
{
      $(this).parent().children(".goodrank").css("height","137px");
      if(jianjiezhiguanMoshiIndex ==1)
      {
            $(this).parent().children(".goodinfo").fadeIn();
            $(this).parent().children(".side-item").fadeIn();
            $(this).parent().children(".goodcomment").fadeIn();
            $(this).parent().children(".morecomment").fadeIn();
            $(this).parent().children(".pictag").fadeIn();

      }
            $(this).parent().css({"z-index":"99"});
}
},

click: function() {
var imgstr =$(this).children("a").outer();

readItem5=readItem4;
readItem4=readItem3;
readItem3=readItem2;
readItem2=readItem1;
readItem1=imgstr;

$('.readed').html('<div class="readeditemsStr" style="background-color: #FF9BA9;width: 60px;height: 24px;border: 1px solid #D70034;color: white;text-align: center;color: rgb(255, 255, 255);font-weight: bold;">刚看过<div><div class="readItem">'+readItem1+readItem2+readItem3+readItem4+readItem5+'</div>');
}
});


$(".item").live({
mouseenter: function() {
            $(this).css({"z-index":"99"});
       var ie = -[1,];
       if(ie)
        {
            $(this).children(".goodimg").children("a").children("img").css({"-moz-box-shadow":"0px 0px 20px #aaa"});
            $(this).children(".goodimg").children("a").children("img").css({"-webkit-box-shadow":"0px 0px 20px #aaa"});
            $(this).children(".goodimg").children("a").children("img").css({"box-shadow":"0px 0px 20px #aaa"});
        }
},
      mouseleave: function() {
       var ie = -[1,];
       if(ie)
       {
            $(this).children(".goodrank").animate({height:0});
            $(this).children(".goodimg").children("a").children("img").css({"-moz-box-shadow":"0px 0px 10px #ccc"});
            $(this).children(".goodimg").children("a").children("img").css({"-webkit-box-shadow":"0px 0px 10px #ccc"});
            $(this).children(".goodimg").children("a").children("img").css({"box-shadow":"0px 0px 10px #ccc"});
            $(this).children(".goodimg").children(".goodtitle").animate({
                height: 0
            });
        }
        else
        {
            $(this).children(".goodrank").css("height","0px");
        }
        
           
      if(jianjiezhiguanMoshiIndex ==1)
      {
            $(this).children(".goodinfo").hide();
            $(this).children(".side-item").hide();
            $(this).children(".goodcomment").hide();
            $(this).children(".morecomment").hide();
            $(this).children(".pictag").hide();

      }
            $(this).css({"z-index":"50"});
        }
    });



 
    $('.toggle').live('click',
    function() {
        if ($(this).parent().siblings(".morecommentbox").css("display") == "none") {
            $(this).html("收起评论");
        } else {
            $(this).html("更多评论");
        }
        $(this).parent().siblings(".morecommentbox").slideToggle("normal",
        function() {
				$container.imagesLoaded(function() {
                    $container.masonry({
                        columnWidth: 238,
                        itemSelector: '.item',
                        isFitWidth: true,
                        isAnimated: true,
                        animationOptions: {
                            duration: 400,
                            easing: 'linear',
                            queue: false
                        }
                    });
                });
        });
    });
 
	$(".favthis a").live('click',
	function(){
		var ctrl = (navigator.userAgent.toLowerCase()).indexOf('mac') != -1 ? 'Command/Cmd':'Ctrl';
		var myloc = $(this).attr("title");
		var mytitle = $(this).parent().parent().siblings(".goodimg").children(".goodtitle").html();
		if(document.all)
		{
			window.external.addFavorite(myloc,mytitle);
		}
		else if(window.sidebar)
		{ 
			window.sidebar.addPanel(mytitle,myloc);
		}
		else{
			top.location = myloc;
			//alert('请用Ctrl+D进行添加');
		}
	});
 
 
       $(".hidecomment").live('click',
	function(){
		$(".goodcomment").hide();
                $(".morecomment").hide();
                $(this).hide();
$(".showcomment").show();
$container.imagesLoaded(function() {
                    $container.masonry({
                        columnWidth: 238,
                        itemSelector: '.item',
                        isFitWidth: true,
                        isAnimated: true,
                        animationOptions: {
                            duration: 400,
                            easing: 'linear',
                            queue: false
                        }
                    });
                });
		}
	);
 
 $(".showcomment").live('click',
	function(){
		$(".goodcomment").show();
                $(".morecomment").show();
                $(this).hide();
$(".hidecomment").show();
$container.imagesLoaded(function() {
                    $container.masonry({
                        columnWidth: 238,
                        itemSelector: '.item',
                        isFitWidth: true,
                        isAnimated: true,
                        animationOptions: {
                            duration: 400,
                            easing: 'linear',
                            queue: false
                        }
                    });
                });
		}
	);
 
});
