﻿(function($) {
	if ($.browser.mozilla) {
		$.fn.disableTextSelect = function() {
			return this.each(function() {
				$(this).css({
					'MozUserSelect' : 'none'
				});
			});
		};
		$.fn.enableTextSelect = function() {
			return this.each(function() {
				$(this).css({
					'MozUserSelect' : ''
				});
			});
		};
	} else if ($.browser.msie) {
		$.fn.disableTextSelect = function() {
			return this.each(function() {
				$(this).bind('selectstart.disableTextSelect', function() {
					return false;
				});
			});
		};
		$.fn.enableTextSelect = function() {
			return this.each(function() {
				$(this).unbind('selectstart.disableTextSelect');
			});
		};
	} else {
		$.fn.disableTextSelect = function() {
			return this.each(function() {
				$(this).bind('mousedown.disableTextSelect', function() {
					return false;
				});
			});
		};
		$.fn.enableTextSelect = function() {
			return this.each(function() {
				$(this).unbind('mousedown.disableTextSelect');
			});
		};
	}
})(jQuery);

window.log = function(){
  log.history = log.history || [];
  log.history.push(arguments);
  if(this.console){
    console.log( Array.prototype.slice.call(arguments) );
  }
};

(function(doc){
  var write = doc.write;
  doc.write = function(q){ 
    log('document.write(): ',arguments); 
    if (/docwriteregexwhitelist/.test(q)) write.apply(doc,arguments);  
  };
})(document);

jQuery.extend(jQuery.easing, {
	def: 'easeInOutCubic',
	swing: function (x, t, b, c, d) {
		return jQuery.easing[jQuery.easing.def](x, t, b, c, d);
	},
	easeInOutCubic: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t + b;
		return c/2*((t-=2)*t*t + 2) + b;
	},
});

function control(evn) {
	if ("mouseenter" == evn.type) {
		$(evn.currentTarget).children("span").stop().animate({
			opacity: 0.7
		});
	} 
	if ("mouseleave" == evn.type) {
		$(evn.currentTarget).children("span").stop().animate({
			opacity: 0
		});
	} 
}

$.fn.switchActive = function(index) {
	var item = $(this);
	$(item).parent().children(".active").removeClass("active");
	$(item).addClass("active");
}

$(document).ready(function(){
	var container = $("#pageScrollContainer");
	var filename;
	
	var defaultName = "1280.html";
	
	if (screen.width <= 1024) {
		filename = "1024.html";
	} else if ((screen.width <= 1280) && (screen.height <= 800)) {
		filename = "1024.html";
	} else if (screen.width <= 1280) {
		filename = "1280.html";
	} else {
		filename = "1280.html";
	}
	
	$(container).load(filename, function(data) {
		var list = $(this).find("li");
		var pixelsPerWheel = 150;
		var currentItem = 0;
		var countItems = list.length - 1;
		
		var ua = navigator.userAgent;
		var isiPad = /iPad/i.test(ua) || /iPhone OS 3_1_2/i.test(ua) || /iPhone OS 3_2_2/i.test(ua);		
		
		$("p.control").bind({
			mouseenter: function(){
				$(this).stop().animate({
						opacity: 0
					},300, function(){
						$(this).animate({
						opacity: 1
						}, 300)
					});
			},
			mouseleave: function(){
				$(this).stop().animate({
						opacity: 1
					},300, function(){
						$(this).animate({
						opacity: 0
						}, 300)
					});
			}

		});

		$("p.control > span").bind({
			mouseenter: function(){
				$(this).stop().animate({
						opacity: 1
					},300, function(){
						$(this).animate({
						opacity: 0.7
						}, 300)
					});
			},
			click: function(e){
				switch($(e.currentTarget).attr("class")) {
					case "first":
						n = 1;
						break;
					case "second":
						n = 2;
						break;
					case "third":
						n = 3;
						break;
					default:
						n = 1;
				}

				if ("left" == $(e.currentTarget).parent().attr("id")) n = -n;			
				currentItem = currentItem + n;
				if (0 >= currentItem) {
					currentItem = 0;
				} else if (countItems <= currentItem) {
					currentItem = countItems;
				}
		
				neededItem = list[currentItem];
				position = $(neededItem).attr("offsetLeft") - ($(container).attr("clientWidth") / 2) + ($(neededItem).attr("offsetWidth") / 2);

				$("p.control").hide();
		
				$(container).stop().animate({
					scrollLeft: position
				}, 1000, "easeInOutCubic", function(){
		
					if (currentItem == countItems) {
						$("p#right.control").hide();
						$("p#left.control").show();
					} else if (0 == currentItem) {
						$("p#right.control").show();
						$("p#left.control").hide();
					} else {
						$("p#right.control").show();
						$("p#left.control").show();
					}
		
					$(neededItem).children("img").animate({
						opacity: 0.6
					},350, "easeInOutCubic", function(){
						$(this).animate({
						opacity: 1
						}, 350, "easeInOutCubic")
					});
				});
			}
		});

		if (isiPad) {
			$("p.control").hide();
		}

		$(container).mousewheel(function(event, delta) {
			$(container).attr("scrollLeft", ($(container).attr("scrollLeft")) + pixelsPerWheel * -delta);
			return false;
		});
		
		$(container).children("ul").show();

	});
	
	$("#qrcode").click(function(){
		$("#qrcode_content").fadeIn("slow", function(){
			$(this).click(function(){
				$(this).fadeOut("slow");
				return false;
			});
		});
	});
	
});

