// JavaScript Document
var selected_item = null;
var selected_img = null;
var selected_gallery_thumb = null;
var selected_gallery_txt = null;
var selected_gallery_img = null;
var moved_gallery_arrow = null;
var gallery_txt = null;
var timer = null;
var item_no = 0;
var colors = null, details = null;
var eventtab = null;
var togle = true;
var zindex = 10;
var zindex2 = 1;
$(function(){
	if($.cookie('current') == null) 
	{
		$("#topspeednews").animate({'height':'60'}, function(){
			$("#close-speed").css({"display":"block"});
			$("#topspeednews p").css({"display":"block"});
		});
		$.cookie('current', 'yes', {expires:7});
	}
	
	$("#writer-pro").toggle();
	
	$(".writer-pro").click(function(){
		$("#writer-pro").toggle('fast');
	});

	var $ui = $('#search');
	$('#advsearch').bind('focus click',function(){
		$ui.find('.sb_down')
		   .addClass('sb_up')
		   .removeClass('sb_down')
		   .andSelf()
		   .find('.sb_dropdown')
		   .show();
	});
	$ui.find('.sb_input').bind('focus click',function(){
		$ui.find('.sb_down')
		   .addClass('sb_up')
		   .removeClass('sb_down')
		   .andSelf()
		   .find('.sb_dropdown')
		   .show();
	});
	$ui.bind('mouseleave',function(){
		$ui.find('.sb_up')
		   .addClass('sb_down')
		   .removeClass('sb_up')
		   .andSelf()
		   .find('.sb_dropdown')
		   .hide();
	});
	$ui.find('.sb_dropdown').find('label[for="all"]').prev().bind('click',function(){
		$(this).parent().siblings().find(':checkbox').attr('checked',this.checked).attr('disabled',this.checked);
	});
	
	$("#close-speed").click(function(){
		$("#topspeednews").animate({'height':'0'}, function(){
			$("#close-speed").css({"display":"none"});
			$("#topspeednews p").css({"display":"none"});
		});
	});
	
	
	colors = new Array("1", ".a", ".b", ".c", ".d", ".e");
	details = new Array("1", ".da", ".db", ".dc", ".dd", ".de");
	/////////////////////////////Start Page//////////////////////////////////////////////
	init();
	/////////////////////////////////////////////////////////////////
	$(colors[1]).animate({opacity:'1'},{duration:100});
	$(colors[1]).css({"z-index":zindex});
	$("#newswedgitsimage li:first").css({"z-index":zindex2});
	$(details[1]).animate({opacity:'1'},{duration:100});
	/////////////////////////Click Event//////////////////////////////////////
	$("#navigationimg li a img").click(function(){
		if($(selected_item).attr('src') == $(this).attr('src')) return;
		clearInterval(timer);
		
		var ele_id = $(selected_item).attr('id');
		
		$(colors[ele_id]).animate({opacity:'0'},{duration:400});
		$(details[ele_id]).animate({opacity:'0'},{duration:400});
		selected_item = this;
		$("#navigationimg li a img").animate({opacity:'.5'},{duration:300});
		var ele_id = $(this).attr('id');
		
		$(colors[ele_id]).animate({opacity:'1'},{duration:100});
		$(colors[ele_id]).css({"z-index":++zindex});
		$(details[ele_id]).animate({opacity:'1'},{duration:100});
		$(details[ele_id]).css({"z-index":++zindex});
		$("#slidecross").animate({"top": ((ele_id - 1) * 60) + 27});
		$(selected_item).animate({opacity:'1'},{duration:0});
		$(selected_img).animate({opacity:'0'},{duration:400});
		
		$('#newswedgitsimage li img#' + ele_id * 10).animate({opacity:'1'},{duration:400});
		
		selected_img = $('#newswedgitsimage li img#' + ele_id * 10);
		$(selected_img).parent().parent().css({"z-index":++zindex2});
		start();
	});
	start();
	
	$("#browsable").scrollable().navigator();
	
	/////////////////////////////////Photo Gallery//////////////////////////////////	
	Galleryinit();
	
	$("#photo-thumb li img").hover(function(){
		
		$("#"+selected_gallery_img).stop().animate({opacity:'0'},{duration:200});
		selected_gallery_img = $(this).attr("id") * 10;
		$("#"+selected_gallery_img).stop().animate({opacity:'1'},{duration:100});
		
		$("#photo-title-txt").html(gallery_txt[selected_gallery_img/1000]);
		$("#photo-arrow").stop().animate({"right":moved_gallery_arrow[selected_gallery_img/1000]},{duration:300});
	}, function(){});
	////////////////////////////////////////////////////////////////////////////////

	SetTabEvent();
	eventtab = $("#todaynews");
	SetMotionEvent();
	
	var oo = 1;
	$("#moreread-txt li").each(function(){
		$(this).addClass("a"+oo);
		oo++;
	});
	var oo = 1;
	$("#report-txt li").each(function(){
		$(this).addClass("a"+oo);
		oo++;
	});
	var oo = 1;
	$("#article-txt li").each(function(){
		$(this).addClass("a"+oo);
		oo++;
	});
	
	$("#reports").click(function(){
		$("#news").removeClass("selected");
		$("#articles").removeClass("selected");
		$(this).addClass("selected");
		
		$("#moreread-txt").css({"display":"none"});
		$("#article-txt").css({"display":"none"});
		$("#report-txt").css({"display":"block"});
	});
	
	$("#news").click(function(){
		$("#articles").removeClass("selected");
		$("#reports").removeClass("selected");
		$(this).addClass("selected");
		
		$("#moreread-txt").css({"display":"block"});
		$("#article-txt").css({"display":"none"});
		$("#report-txt").css({"display":"none"});
	});
	
	$("#articles").click(function(){
		$("#news").removeClass("selected");
		$("#reports").removeClass("selected");
		$(this).addClass("selected");
		
		$("#moreread-txt").css({"display":"none"});
		$("#article-txt").css({"display":"block"});
		$("#report-txt").css({"display":"none"});
	});
	
	////////////////////////////////////Video/////////////////////////////////////////
	initVideo();
	
	var motion = Array(30, 120, 205);
	$(".video-ul1 li.video-li").hover(function(){
		var span = $(this).find("span").html();
		$(".show-details span").html(span);
		if($(this).html() == $(".video-ul1 li.video-li:first").html())
			$(".img-arrow").stop().animate({"right":30});
		else if($(this).html() == $(".video-ul1 li.video-li:last").html())
			$(".img-arrow").stop().animate({"right":205});
		else
			$(".img-arrow").stop().animate({"right":120});
	});
	
	
	$(".video-ul2 li.video-li").hover(function(){
		var span = $(this).find("span").html();
		$(".show-details2 span").html(span);
		if($(this).html() == $(".video-ul2 li.video-li:first").html())
			$(".img-arrow2").stop().animate({"right":30});
		else if($(this).html() == $(".video-ul2 li.video-li:last").html())
			$(".img-arrow2").stop().animate({"right":205});
		else
			$(".img-arrow2").stop().animate({"right":120});
	});
	
	$(".video-ul2").hover(function(){
		$(".show-details").stop().animate({"height":"0"}, function(){
			$(this).css({"display":"none"});
			$(".show-details2").css({"display":"block"});
		});
		
		$(".show-details2").stop().animate({"height":"80"});
		$(".show-details2 span").html($(".video-ul2 li:first span").html());
	}, function(){});
	$(".video-ul1").hover(function(){
		$(".show-details").stop().animate({"height":"79"}, function(){
			$(this).css({"display":"block"});
			$(".show-details").css({"display":"block"});
		});
		 
	}, function(){});
	
	//////////////////////////////////////////////////////////////////////////////
	CreateCarousle();
});
function CreateCarousle()
{
	var xy = 0;
	var a = 1;
	var arr = $("#bbcarsoule ul li");
	var li_width = $("#bbcarsoule ul li").width();
	var b =  arr.length;
	var imgarr = Array();
	$("#bbcarsoule ul li").each(function(){
		imgarr[a++] = $(this).find('.carsouleimg').attr('src');
	});
	a = 1;
	$("#bbprev_btn").click(function(){
		if(a <= 1) 
		{
			xy = li_width * (b-1);
			$("#bbcarsoule ul li").stop().animate({left:-xy},'slow');			
			a = b;
			$("#showthumb-left").attr('src', imgarr[a - 1]);
			return;
		}
		xy -= li_width;
		$("#bbcarsoule ul li").stop().animate({left:-xy},'slow');
		a -= 1;
		if (a == 1)
		{
			$("#showthumb-left").attr('src', imgarr[b]);
		}
		else {
			$("#showthumb-left").attr('src', imgarr[a - 1]);
		}
	});	
	$("#bbnext_btn").click(function(){
		if(a >= b)
		{
			$("#bbcarsoule ul li").stop().animate({left:0},'slow');
			xy = 0;
			a = 1;
			$("#showthumb-rigth").attr('src', imgarr[2]);
		 	return;
		}
		xy += li_width;
		$("#bbcarsoule ul li").stop().animate({left:-xy},'slow');
		a += 1;
		if (a == b)
		{
			$("#showthumb-rigth").attr('src', imgarr[1]);
		}
		else {
			$("#showthumb-rigth").attr('src', imgarr[a + 1]);
		}
	});	
	$("#bbprev_btn").hover(function(){
		$(this).attr('src', 'images/bbleftarrow.gif');
		$("#showthumb-left").css({'display':'block'});
		if (a == 1)
		{
			$("#showthumb-left").attr('src', imgarr[b]);
		}
		else {
			$("#showthumb-left").attr('src', imgarr[a - 1]);
		}
	}, function(){
		$(this).attr('src', 'images/leftarrow.gif');
		$("#showthumb-left").css({'display':'none'});
	});	
	$("#bbnext_btn").hover(function(){
		$(this).attr('src', 'images/bbrightarrow.gif');
		$("#showthumb-rigth").css({'display':'block'});
		if (a == b)
		{
			$("#showthumb-rigth").attr('src', imgarr[1]);
		}
		else {
			$("#showthumb-rigth").attr('src', imgarr[a + 1]);
		}
	}, function(){
		$(this).attr('src', 'images/rightarrow.gif');
		$("#showthumb-rigth").css({'display':'none'});
	});
}
function initVideo()
{
	$(".show-details span").html($(".video-ul1 li:first span").html());
}
function Galleryinit()
{
	var i = 1;
	
	$("#photo-gallary li a img").each(function(){
		$(this).attr('id', i * 1000);
		i++;
	});	
	i = 1;
	$("#photo-thumb li img").each(function(){
		$(this).attr('id', i*100);
		i++;
	});	
	$("#photo-gallary li img").animate({opacity:'0'},{duration:0});
	$("#photo-gallary li:first img").animate({opacity:'1'},{duration:0});
	
	gallery_txt = new Array("1", ".a", ".b", ".c", ".d", ".e");
	var i = 1;
	$("#photo-txt li").each(function(){
		gallery_txt[i++] = $(this).html();
	});
	$("#photo-title-txt").html(gallery_txt[1]);

	selected_gallery_img = 1000;
	selected_gallery_thumb = 100;
	selected_gallery_txt = 1;
	moved_gallery_arrow = new Array(0, 15, 75, 132, 192, 250);
}

function start()
{
	timer = setInterval(function(){		
		if($(selected_item).attr('id') == item_no)
		{
			$("#slidecross").animate({"top":"27"});
			$(selected_item).animate({opacity:'.5'},{duration:0});
			$(selected_img).animate({opacity:'0'},{duration:400});
			var ele_id = $(selected_item).attr('id');
			$(colors[ele_id]).animate({opacity:'0'},{duration:400});
			$(details[ele_id]).animate({opacity:'0'},{duration:400});
			selected_item = $("#navigationimg li:first a img");
			selected_img = $("#newswedgitsimage li:first img");
			
			$(selected_item).animate({opacity:'1'},{duration:0});
			$(selected_img).animate({opacity:'1'},{duration:400});
			$(selected_img).parent().parent().css({"z-index":++zindex2});
			$(colors[1]).animate({opacity:'1'},{duration:100});
			
			$(colors[1]).css({"z-index":++zindex});
			$(details[1]).animate({opacity:'1'},{duration:100});
			$(details[1]).css({"z-index":++zindex});
		}
		else{
			$(selected_item).animate({opacity:'.5'},{duration:0});
			$(selected_img).animate({opacity:'0'},{duration:400});
			
			var ele_id = $(selected_item).attr('id');
			$(colors[ele_id]).animate({opacity:'0'},{duration:400});
			$(details[ele_id]).animate({opacity:'0'},{duration:400});
			$("#slidecross").animate({"top": (ele_id * 60) + 27});
			ele_id++;
			$(colors[ele_id]).animate({opacity:'1'},{duration:100});
			
			$(details[ele_id]).animate({opacity:'1'},{duration:100});
			selected_item = $('#navigationimg li a img#' + ele_id);
			selected_img = $('#newswedgitsimage li img#' + ele_id * 10);
			
			$(selected_item).animate({opacity:'1'},{duration:0});
			$(selected_img).animate({opacity:'1'},{duration:400});	
			$(selected_img).parent().parent().css({"z-index":++zindex2});
			$(colors[ele_id]).css({"z-index":++zindex});
			$(details[ele_id]).css({"z-index":++zindex});
		}
	},30000);
}

function init()
{
	var i = 1;
	
	$("#navigationimg li a img").each(function(){
		$(this).attr('id',i);
		i++;
		item_no++;
	});
	
	i = 1;
	$("#newswedgitsimage li img").each(function(){
		$(this).attr('id',i*10);
		i++;
	});
	
	selected_item = $("#navigationimg li:first a img");
	selected_img = $("#newswedgitsimage li:first img");

	$("#navigationimg li a img").animate({opacity:'.5'},{duration:0});
	$("#navigationimg li:first a img").animate({opacity:'1'},{duration:0});
	
	$("#newswedgitsimage li img").animate({opacity:'0'},{duration:0});
	$("#newswedgitsimage li:first img").animate({opacity:'1'},{duration:0});
	
	$("#navigationimg li a img").hover(function(){
			showAllImages(this);
		},function(){
			hideAllImages(this);
	});
}

function showAllImages(ele)
{
	if($(selected_item).attr('src') == $(ele).attr('src')) return;
	$(ele).animate({opacity:'1'},{duration:100});
}

function hideAllImages(ele) 
{
	if($(selected_item).attr('src') == $(ele).attr('src')) return;
	$(ele).animate({opacity:'.4'},{duration:100});
}
var allnewsh, todayh = 0;
var allnewsmotion = 1, todaymotion = 1;
var allnewsdown = 1, todaydown = 1;
function SetTabEvent()
{
	todayh = $("#todaynews").height();
	$("#allnews1").click(function(){
		$("#todaynews").css({"display":"none"});
		$("#todaynewsbody").css({"display":"none"});
		
		$("#allnews").css({"display":"block"});
		$("#allnewsbody").css({"display":"block"});
		
		$(this).addClass("selected");
		$("#todaynews1").removeClass("selected");
		eventtab = $("#allnews");
		allnewsh = $("#allnews").height();
	});
	
	$("#todaynews1").click(function(){
		$("#todaynews").css({"display":"block"});
		$("#todaynewsbody").css({"display":"block"});
		
		$("#allnews").css({"display":"none"});
		$("#allnewsbody").css({"display":"none"});
		
		$(this).addClass("selected");
		$("#allnews1").removeClass("selected");
		eventtab = $("#todaynews");
	});
}
function SetMotionEvent()
{
	$("#motionup").click(function(){
		if($(eventtab).attr("id") == "todaynews")
		{
			if(todaydown == 1) return;
			$(eventtab).stop().animate({"top":todaydown * 150},{duration:2000});
			todaymotion--;
			todaydown++;
		}
		else if($(eventtab).attr("id") == "allnews")
		{
			if(allnewsdown == 1) return;
			$(eventtab).stop().animate({"top":allnewsdown * 150},{duration:2000});
			allnewsmotion--;
			allnewsdown++;
		}
	});
	
	$("#motiondown").click(function(){
		if($(eventtab).attr("id") == "todaynews")
		{
			if((todaymotion * 150) > (todayh - 100))
				return;
			$(eventtab).stop().animate({"top":todaymotion * -150},{duration:2000});
			todaymotion++;
			todaydown--;
		}
		else if($(eventtab).attr("id") == "allnews")
		{
			if((allnewsmotion * 150) > (allnewsh - 100))
				return;
			$(eventtab).stop().animate({"top":allnewsmotion * -150},{duration:2000});
			allnewsmotion++;
			allnewsdown--;
		}
	});
}
    $(document).ready(function() {
        

$("#loading").css({'display':'none'});
$("#mainslider").css({'display':'block'});


    });


