/* ====== Base Site class ====== */
/*
*  rely on jQuery core
*  Accord method rely on jQuery.UI.core,
*  jQuery.UI.Accordion
*/
function Site(isBanner, isNavig, isAccord, isList){
	
	/**** Initialize class methods ****/

	this.Ban = function()
	{
		$("#banimg1, #banimg2, #banimg3").hide();
		setTimeout(function(){
			$("#banner ul").fadeIn(1000);
		}, 500);
		setTimeout(function(){
			$("#banimg1").fadeIn(1500);
		}, 1500);
		setInterval(this.Next, 5000);
	}

	var pos = 1;
	var cur_img;
	var cur_txt;
	var img = "#banimg";
	var txt = "#bansp";

	this.Next = function()
	{
		cur_img = img + pos;
		cur_txt = txt + pos;
		
		$(cur_img).fadeOut(1000);
		$(cur_txt).fadeOut(500);
		
		pos++;
		if(pos > 3) { pos = 1; }
		
		cur_img = img + pos;
		cur_txt = txt + pos;
		
		setTimeout(function()
		{
			$(cur_img).fadeIn(1500);
			$(cur_txt).fadeIn(500);
		}, 1010);
		
	}

	this.Nav = function()
	{
		$("#navig a").hover(function() {
			$(this).animate({ borderTopColor: "#FC0" }, 300);
		},function() {
			$(this).animate({ borderTopColor: "#EEE" }, 500, function(){$(this).css("border-top","2px solid transparent"); });
		});
	}
	
	this.Accord = function()
	{
		$(".cont_list").accordion({ header: "h3" });
	}
	
	this.List = function()
	{
		$(".cont_list li:odd").css("background-color", "#E6DFDD");
	}
	
	/*** Constructor initializing ***/
	
	$("img").cacheImage();	// Cache-images
	
	if ( $.browser.msie ){
		if( $.browser.version < 8 ){
			$("#sidepan").css("margin", "0px -8px");
			$("#sideban .sb-div").css("margin-top", "50px");
			$("#sidetel").css("padding", "15px 10px 0px 10px");
			
			if( $.browser.version < 7 ){
				$("img[src$='.png']").ifixpng();
				$("#headline, #footline, #banner, #logo").ifixpng();
				$('img, span').ifixpng();
				setTimeout(function(){$("img[src$='.png']").ifixpng();}, 500);
			}
		}
	}

	if(isBanner == 'ban' || isBanner == true){	this.Ban();    }
	if (isNavig == 'nav' || isNavig == true) {	this.Nav();    }
	if(isAccord == 'acr' || isAccord == true){	this.Accord(); }
	if  (isList == 'lst' || isList == true)  {  this.List();   }
}

/* ====== IMG Caching - Preload ====== */
/*
*  rely on jQuery core 
*/
 (function ($) {
   $.extend($, {
     cacheImage: function (src, options) {
       if (typeof src === 'object') {
         $.each(src, function () {
           $.cacheImage(String(this), options);
         });
       }

       var image = new Image();

       options = options || {};

       $.each(['load', 'error', 'abort'], function () { // Callbacks
         var e = String(this);
         if (typeof options[e] === 'function') { $(image)[e](options[e]); }
       });

       image.src = src;

       return image;
     }
   });

   $.extend($.fn, {
     cacheImage: function (options) {
       return this.each(function () {
         $.cacheImage(this.src, options);
       });
     }
   });
 })(jQuery);

/* ====== PNG fix for IE ====== */
/*
*  rely on jQuery core 
*/
(function($) {
	
	$.ifixpng = function(customPixel) {
		$.ifixpng.pixel = customPixel;
	};
	
	$.ifixpng.getPixel = function() {
		return $.ifixpng.pixel || '/gfx/blank.gif';
	};
	
	var hack = {
		ltie7  : $.browser.msie && /MSIE\s(5\.5|6\.)/.test(navigator.userAgent),
		filter : function(src) {
			return "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true,sizingMethod=crop,src='"+src+"')";
		}
	};
	
	 
	$.fn.ifixpng = hack.ltie7 ? function() {
    	return this.each(function() {
			var $$ = $(this);
			var base = $('base').attr('href'); 
			if ($$.is('img') || $$.is('input')) { 
				if ($$.attr('src').match(/.*\.png([?].*)?$/i)) { 
					var source = (base && $$.attr('src').substring(0,1)!='/') ? base + $$.attr('src') : $$.attr('src');
					$$.css({filter:hack.filter(source), width:$$.width(), height:$$.height()})
					  .attr({src:$.ifixpng.getPixel()})
					  .positionFix();
				}
			} else {
				var image = $$.css('backgroundImage');
				if (image.match(/^url\(["']?(.*\.png([?].*)?)["']?\)$/i)) {
					image = RegExp.$1;
					$$.css({backgroundImage:'none', filter:hack.filter(image)})
					  .positionFix();
				}
			}
		});
	} : function() { return this; };
	
 
	$.fn.iunfixpng = hack.ltie7 ? function() {
    	return this.each(function() {
			var $$ = $(this);
			var src = $$.css('filter');
			if (src.match(/src=["']?(.*\.png([?].*)?)["']?/i)) {
				src = RegExp.$1;
				if ($$.is('img') || $$.is('input')) {
					$$.attr({src:src}).css({filter:''});
				} else {
					$$.css({filter:'', background:'url('+src+')'});
				}
			}
		});
	} : function() { return this; };
	
 
	$.fn.positionFix = function() {
		return this.each(function() {
			var $$ = $(this);
			var position = $$.css('position');
			if (position != 'absolute' && position != 'relative') {
				$$.css({position:'relative'});
			}
		});
	};
})(jQuery);
