$(document).ready(function(){
	$("#columns ul li.widget").corner("5px");
	if($('#pfs').length!=0) {
		if($('#pfs').html()=='True')
			fullScreen(true);
	}
	iNettuts.init();

	$('#torec_movieSubs_data').css('display','');
	$('#torec_seriesSubs_data').css('display','');
	$('#last_movieSubs_data').css('display','');
	$('#last_seriesSubs_data').css('display','');
	$('#loading_div').css('display','none');

	createSubsNav();
	$('#columns').css('visibility','visible');
	createSimpleTabs("simpleTabs2","/ajax/main/HDSubs.txt");
	createSimpleTabs("oldLastSubs","/ajax/main/oldSubs.txt");
	createSimpleTabs("lastSubsDays","/ajax/main/lastSubsDays.asp");
	createSimpleTabs("movieKolnoa","/ajax/main/Kolnoa_txt.asp");
	createSimpleTabs("lastForumMsg","/ajax/main/lastForumMsg.asp");

	//news
	var newsoption1 = {
		firstname: "mynews",
		secondname: "showhere",
		thirdname:"news_display",
		fourthname:"news_button",
		playingtitle:"עדכון נוכחי: ",
		nexttitle:"העדכון הבא: ",
		prevtitle:"העדכון הקודם: ",
		newsspeed:'4000',
		effectis:'0',
		mouseover:true,
		imagedir:'/js/EasyNews/'
	}
	$.init_news(newsoption1);

	if($('#news_button').length) {
		var myoffset=$('#news_button').offset();
		var mytop=myoffset.top-1;
		$('#news_button').css({top:mytop});
	}
	//END news

	yosbanner('s');
});

	PageClick = function(pageclickednumber,idN) {
		$("#"+idN+' ul>li.loading').html('טוען...');
		var content = "#"+idN.replace('pager','data');
		var addedres='';
		var tpages = 3;
		
		if($('div.body-main').css('width').replace('px','')<1536-25 && $('div.body-main').css('width').replace('px','')>998) {
			addedres = 'res_';
			tpages = 4;
		} else {
			tpages = 3;
		}
		$.ajax({
			type: "GET",
			url: '/ajax/main/'+idN+'/'+idN+'_'+addedres+pageclickednumber+'.txt',
			success: function(html) {
				$(content+' .jcarousel_posters').remove();
				$(content).html(html+'<div class="pager" id="'+idN+'"></div>');
				$("#"+idN).pager({ pagenumber: pageclickednumber, pagecount: tpages, buttonClickCallback: PageClick, idName: idN });
			}
		});
	}

function createSubsNav() {
	var subsArr = new Array('torec_movieSubs_pager','torec_seriesSubs_pager','last_movieSubs_pager','last_seriesSubs_pager');
	var tpages = 3;
	for(s=0;s<subsArr.length;s++) {
		if($('#'+subsArr[s]).length>0) {
			if($('div.body-main').css('width').replace('px','')<1536-25 && $('div.body-main').css('width').replace('px','')>998)
				tpages = 4;
			else
				tpages = 3;
			$('#'+subsArr[s]).pager({ pagenumber: 1, pagecount: tpages, buttonClickCallback: PageClick, idName: subsArr[s] });
		}
	}
}
function makeToolTip(obj) {
	$(document).ready(function(){
		tcontent = $('#'+$('#'+obj).attr('title')).html();
		$('#'+obj).attr('title','');
		$('#s'+obj).wTooltip({
				content: tcontent,
				className: 'tooltip',
				offsetY: 30,
				offsetX: -150,
				delay: 100
		  });
		//$('#s'+obj).mouseover();
		$('#s'+obj).corner("7px");
	});
}

function makeToolTipLink(obj) {
	$(document).ready(function(){
		tcontent = $('#'+$('#'+obj).attr('title')).html();
		$('#'+obj).attr('title','');
		$('#s'+obj).wTooltip({
				content: tcontent,
				className: 'tooltip',
				offsetY: -220,
				offsetX: -150
		  });
	});
}

function createSimpleTabs(divName,fileName) {
		$.jtabber({
			mainLinkTag: "#"+divName+"-nav a", // much like a css selector, you must have a 'title' attribute that links to the div id name
			activeLinkClass: "simpleTabs-nav-selected", // class that is applied to the tab once it's clicked
			hiddenContentClass: "simpleTabs-content", // the class of the content you are hiding until the tab is clicked
			showDefaultTab: null, // 1 will open the first tab, 2 will open the second etc.  null will open nothing by default
			showErrors: true, // true/false - if you want errors to be alerted to you
			effect: 'fade', // null, 'slide' or 'fade' - do you want your content to fade in or slide in?
			effectSpeed: 'fast', // 'slow', 'medium' or 'fast' - the speed of the effect,
			mainDiv : divName,
			datafile : fileName
		})
}

function linkTo(link) {
	location.href=link;

}

function makeImgPreview(tmpID) {
	$('ul#'+tmpID+' a').imgPreview({
		containerID: 'imgPreview',
		srcAttr: 'rel',
		imgCSS: {
			height: 120
		},
		onShow: function(link){
			$('<span>' + link.name + '</span>').appendTo(this);
		},
		onHide: function(link){
			$('span', this).remove();
		}
	});
}

function needToLogin() {
		$.weeboxs.open('חובה להתחבר לאתר על מנת<br>להשתמש באפשרות זו.',{type:'error',title:'שגיאה',showCancel:false});
}

function showContentCats(category) {
	if($('.fsButton').attr('value').indexOf('3')!=-1)
		var fs = false;
	else
		var fs = true;
	$(".addContent").show('blind');
	$(".addContent .content").html('<img src="/images/sloading.gif" alt="טוען" style="vertical-align: middle;" /> <strong>טוען נתונים...</strong>');
	$.get('/ajax/main/mainContent_cats.asp',{cat:category,pfs:fs},function(data) {
		$(".addContent .content").html(data);
	});
}

function resetDefault() {
	$.weeboxs.open('איפוס הגדרות לברירת מחדל ימחק את כל התכנים שלך<Br>בעמוד ויחזיר את ברירת המחדל של האתר.<br>האם ברצונך להמשיך?',{type:'box',title:'איפוס לברירת מחדל',width:400,okBtnName:'איפוס',onok:function() {
			$.get('/ajax/main/cookieDefault.asp',function(data) {
				location.href = location.href;
			});
		}
	});
}

function fullScreen(widthOnly) {
	if(screen.width<1280 && !widthOnly) {
		$.weeboxs.open('אפשרות זו זמינה אך ורק למשתמשים בעלי<br>רזולוציה בעלת רוחב מינימאלי של 1280 פיקסלים.',{type:'error',title:'שגיאת רזולוציה',width:400,okBtnName:'סגור',showCancel:false});	
		return false;
	}
	var cwidth = screen.width-25;
	var columnWidth = (cwidth/3)+'px';
	if($('.fsButton').attr('value').indexOf('3')!=-1)
		$('.fsButton').attr('value','צמצם ל-2 טורים');
	else
		$('.fsButton').attr('value','הרחב ל-3 טורים');
	if(!widthOnly) {
		if($('div.body-main').css('width')==cwidth+"px") {
			cwidth = "998";
			columnWidth = "50%";
			if($.browser.msie) {
				$('<span id="cancelFS" style="display:none;">true</span>').appendTo('body');
				iNettuts.savePreferences();
			} else {
				$('#column3').append($('#column5').html());
				$('#column5').remove();
			}
		}
		else
			$('#column1').after('<ul id="column5" class="column"></ul>');
	}
	if($('#cancelFS').length==0) {
		$('div.body-main').css('width', cwidth+"px");
		$('#columns .column').css('width', columnWidth);
		$('#columns').css('width', cwidth+"px");
		$('#column4').css('width', cwidth+"px");
		$('#column2').css('width', cwidth+"px");
		if(!widthOnly) {
			if(cwidth<1536-25)
				createSubsNav();
			$(iNettuts.settings.columns).sortable('destroy');
			iNettuts.makeSortable();
			iNettuts.savePreferences();
		}
	}
}

//	yosBannerFloat
function yosbanner(action) {
	if(action=="s" && $('#yosFloatBanner').length) {
			$('#yosFloatBanner').css('display','none');
		if(screen.width>1040 && $('#yosFloatBanner').length)
			$('#yosFloatBanner').css('display','');
		else if(screen.width<1040 && $('#yosFloatBanner').length)
			$('#yosFloatBanner').css('display','none');
	}
	else if($('#yosFloatBanner').length) {
		if(screen.width>1040&& $('#yosFloatBanner').length) {
			$('#yosFloatBanner').css('display','none');
		}
	}
	else
		var xx = setTimeout("yosbanner('s')",1500);
}

