﻿// JScript File

var LastIndex = 0;

$(document).ready(function(){
    SetRightNavBar();
    
    $(".SmallPic a").each(function(){
        var thisElement = $(this);
        thisElement.hover(function() {
            ChangeMainPicLink(this,$(this).attr('title'), $(this).attr('subtitle'),$(this).attr('imgsrc'), $(this).attr('index'),'in');
        },
        function() {
            ChangeMainPicLink(this,$(this).attr('title'), $(this).attr('subtitle'),$(this).attr('imgsrc'), $(this).attr('index'),'out');
        }
        );
    });
    
//    $(".Section .Item").hover(
//      function () {
//      var SubTitle = $(this).children(".Left").children(".SubTitle");
//        SubTitle.css("color","#fff");
//      }, 
//      function () {
//      var SubTitle = $(this).children(".Left").children(".SubTitle");
//        SubTitle.css("color","#83838A");
//      }
//    );
        
    $('a.top').click(function(){
         $('html, body').animate({scrollTop: '0px'}, 600);
         return false;
    });


}); 
function ChangeMainPicLink(id,title,subTitle, imgSrc, index,action)
{
    
    $('.MainPageTopFloats .Selected').removeClass('Selected');
    $(id).parent().attr('class', 'SmallPic Selected');
    $('#floatTitle').html(title);
    $('#floatSubTitle').html(subTitle);
    $('#floatImage').attr('src',imgSrc);
    $('#floatImage').attr('title',title);
    $('#floatImage').parent().attr('href',$(id).attr('href'));
//    if(action=='in')
//    {
//        var strBottom = String($('.Float').css('bottom')).substring(3,0);
//        var bottom = parseInt(strBottom);
//        
//        if(LastIndex!=index)
//        {
//            if(index>LastIndex)
//            {
//                $('.Float').css('bottom',bottom - 59);
//            }
//            else
//            {
//                $('.Float').css('bottom',bottom + 59);
//            }
//        }
//        LastIndex = index;
//    }
    
}

function ChangeSection()
{
    if($('#DefaultSection').css('display') == 'block')
    {
        $('#DefaultSection').hide();
        $('#MoreSection').show();
    }
    else
    {
        $('#MoreSection').hide();
        $('#DefaultSection').show();
    }
    document.location="#";
}

function bookmarksite(title,url)
{
    if (window.sidebar) // firefox
        window.sidebar.addPanel(title, url, "");
    else if(window.opera && window.print){ // opera
        var elem = document.createElement('a');
        elem.setAttribute('href',url);
        elem.setAttribute('title',title);
        elem.setAttribute('rel','sidebar');
        elem.click();
    }
    else if(document.all)// ie
        window.external.AddFavorite(url, title);
}

function changeVodSource(VodID)
{
	$('#IPlayer').attr('src','http://switch5.castup.net/Customers/Castup/v_gray_400x300/Design.asp?clipurl=http://switch3.castup.net/cunet/gm.asp?ClipMediaID=' + VodID + '&ak=null');
//	return false;
}
function SetRightNavBar()
{
    $('.MagazineMenu > li > div').click(function(){ 
          thisElement = $(this);
          IsContainsOpen = thisElement.hasClass('Open');
          thisElement.siblings('ul').toggleClass('Open').slideToggle(500,function(){if(IsContainsOpen)thisElement.toggleClass('Open');});
          if(!IsContainsOpen)thisElement.toggleClass('Open');
    });
}

function ValidateNewResponse(ArticleId)
{
    var flag = true;
    
    $(".Responses .New .Body .Text").each(function(){
       if($(this).children().val()=='')
        {
            $(this).siblings('.Label').addClass('Red').fadeOut().fadeIn().fadeOut().fadeIn();
            flag = false;
        }
       else
        $(this).siblings('.Label').removeClass('Red');
    });
    
    if(flag)
    {
         $.post("/Handlers/HandleArticleResponses.ashx",
         {
             ArticleId: ArticleId,
             Title: $('#tbTitle').val(),
             Author: $('#tbAuthor').val(),
             Text: $('#tbText').val()
         },
         function(data){
            $('#lblSubmitResponse').fadeOut().fadeIn().fadeOut().fadeIn().fadeOut().fadeIn();
            $('#tbTitle').val('');
            $('#tbText').val('');
         });
    }
}

