var mobileUtil = {
		isIPad: function(){
			return (navigator.userAgent.indexOf('iPad') != -1);
		},
		isIPhone: function(){
			return (navigator.userAgent.indexOf('iPhone') != -1);
		},
		isIPod: function(){
			return (navigator.userAgent.indexOf('iPod') != -1);
		},
		isAppleMobDevice: function(){
			return (this.isIPad() || this.isIPhone() || this.isIPod());
		},
	    hideURLBar: function() {
	        setTimeout(function() {
	            scrollTo(0, 0);
	        }, 50);
	    }
};
var start_page = {
	init: function(){
		 $(".small_thumbs ul li").each(function(){
			text = $(this).html();
			$(this).html("<table><tr><td>"+text+"</td></tr></table>");
		 });
		 $('.small_thumbs ul li').hover(function(){$('>table',this).fadeIn(300)},
				 function(){$('>table',this).fadeOut(300);});
		$("#slider").easySlider({
			prevId: ".previous",
			nextId: ".next",
			auto: true,
			fade_overlay: true,
			continuous: true,
			pause:	7000
		});
		
	}
	
};
var full_page = {
		init: function(){
			$("#slider_full").easySlider({
				controlsSwitch: true
			});
			  $("a.fancy").live("click", function(e) {e.preventDefault();
				     $(this).filter(':not(.fb)').fancybox().addClass('fb');
				     $(this).triggerHandler('click');
				  });
			
			if ($.browser.msie) {
				$('div.two_columns').columnize({ width: 301});
			}
			$('.form_col input, .form_col textarea').each(function(){
				$(this).data('f_title',$(this).val());
			});
			
			$('.form_col input, .form_col textarea').bind("focus", function(){
				if ($(this).attr('name') != 'submit' && $(this).val() == $(this).data('f_title')){
					$(this).val("");
				};
			});
			$('.form_col input, .form_col textarea').bind("focusout", function(){
				if ($(this).val() == ''){
					$(this).val($(this).data('f_title'));
				}
			});
		}
		
};
var list_page = {
		to_top: function(){
			$('a.to_top').live('click', function() {
				$('body,html').animate({scrollTop:0},300);
				return false;
			});
		},
		add_content: function(){
			var status = 1;
			$(window).bind('scroll',function(){
				pt = parseInt(($(window).scrollTop()/$(window).height())*100);
				//alert(pt);
				if (((pt > 40) && (status == 1)) || (mobileUtil.isAppleMobDevice() && pt >10)){
					$(window).unbind('scroll');
					var sid = $("div#articles-list>ul>li:last").attr("rel");
					var mod = (typeof(module_id) !== 'undefined')? module_id:'';
					if ((typeof(sid) !== 'undefined')&& (typeof(mod) !== 'undefined')){
						$.ajax({
							url: './',
							data: {oper:'getdata', 
								pos: sid,
								module: mod},
							dataType: 'json',
							success: function(r){
									if (r.status == 1) {
											$("div#articles-list>ul").append(r.data);
											list_page.add_content();
									}else { status = 0;}						
							}
						});
					}
				}

			});
			
		},
		init: function(){
				list_page.to_top();
				list_page.add_content();
		}
		
}
var global_set = {
		init: function(){
			$(window).bind("unload", function() {});
			$("body").hide();
			$("body").fadeIn(700);
			$("a.transition").live('click',
				function(event){
					event.preventDefault();
					linkLocation = this.href;
					$("body").fadeOut(500, global_set.redirectPage);
				});
			if (mobileUtil.isAppleMobDevice()) {
		        $(window).load(function() {
		        	mobileUtil.hideURLBar();
		        	 setTimeout(function() {
		        		 global_set.changeFooterPosition();},100);
			        });

				//$(".bottom_line").css('position', 'absolute');
				$(document).bind('touchstart', function(){$('.bottom_line').hide();});
				$(document).bind('touchend', function(){$('.bottom_line').show();});
				$(document).bind('scroll', function() {
					  global_set.changeFooterPosition();
					});
			}
			
		},
		redirectPage: function() {
			window.location = linkLocation;
		},
		changeFooterPosition: function() {
			$('.bottom_line').css('top', window.innerHeight + window.scrollY - 7 + "px");
		}

}
$(document).ready(function(){
	global_set.init();
	start_page.init();
	full_page.init();
	list_page.init();
});
