/**
Generated	: April 19th 2010 09:34:32
ismail ŞAHAN
********************************************************************************************/


/**
 * jQuery .is(':visible') bug fixed
*********************************************************************************/
function _e(){
		/*
		* Language set
		* Use:_e(lang variable [, %1 optional [, %2 optional [, ....] ] ] );
		*/
		var args=_e.arguments;
		var arglen=args.length;
		var result='';
		if(arglen){
			var lang_var=args[0];
			result=lng[lang_var];
			for(var i=arglen-1;i>0;i--){
				result=result.replace('%'+i,args[i]);
			}
		}
		return result;
	}
	
 (function($) {
	$.fn.SlideIS = function(options){
		return this.each(function(i){
			var el = this
			el.current =  0;
			el.$this = $(this).css({position:'relative'});
			el.list = el.$this.find('.slide-item');
			el.opt = $.extend({}, SlideIS, options);
			el.index = i;
			el.total = el.list.size();
			el.tID = null;
			var w,h;
			switch(el.opt.direction){
				case 'horizontal':
					width = el.total * el.opt.width;
					height = el.opt.height;
					break;
				case 'vertical':
					width = el.opt.width;
					height = el.total *el.opt.height;
					break;
				default:
					width = el.total *el.opt.width;
					height = el.total *el.opt.height;
					break;
			};
			el.itemContainer = $('<div class="item-container" style="height:'+el.opt.height+'px;position:relative;overflow:hidden">')
								.css({height:el.opt.height,width:el.opt.width,position:'relative',overflow:'hidden'});
			el.$this.css({height:height,width:width});
			
			el.$this.wrap(el.itemContainer);
			el.pagination = $('<div class="pagination">');
			el.$this.parent().parent().append(el.pagination);
			var num = $('<ul class="pages">').appendTo(el.pagination);
			var pos = {x:0,y:0};
			var n;
			el.list.each(function(j){
			 	var current = '';
				if(j == 0) current = 'current';
				//var $a = $('<a href="#'+(j)+'" class="spr slide-link '+current+'">'+(j+1)+'</a>').click(function(){
					var $a = $('<a href="#'+(j)+'" class="spr slide-link '+current+'"> </a>').click(function(){
					if(el.opt.autoplay){
						window.clearInterval(el.tID);
						autoplay();
					}
					var href = this.index;
					el.pagination.find('.current').removeClass('current');
					$(this).addClass('current');
					var params = {};
					if( el.opt.direction == 'diagonal'){
						params = {right:(el.opt.width*href),bottom:(el.opt.height*href)}
					}
					else if( el.opt.direction == 'vertical'){
						params = {bottom:(el.opt.height*href)}
					}
					else if( el.opt.direction == 'horizontal'){
						params = {right:(el.opt.width*href)}
					};
					el.$this.stop().animate(params,{
					  duration: el.opt.speed,
					  easing: el.opt.ease, 
					  complete: function() { 
					  	// alert('ok');
					  }
					 });
					el.index = href;
					return false;
				});
				
				n = $a.get(0);
				n.index = j;
				

				$('<li class="slideIS-item">').appendTo(num).append($a);

				if( el.opt.direction == 'diagonal'){
					pos.x = j * el.opt.width;
					pos.y = j * el.opt.height;
				}
				else if( el.opt.direction == 'horizontal'){
					pos.x = j * el.opt.width;
				}
				else if( el.opt.direction == 'vertical'){
					pos.y = j * el.opt.height;
				};

				var list = $(this).css({height:el.opt.height,width:el.opt.width,position:'absolute',left:pos.x, top:pos.y});
				list.show();
				/*var $loader = $('<div class="loading">').appendTo(list);
				var image = new Image();
				image.onload = function(){
					image.onload = null;
					$loader.fadeOut();
					img.css({marginLeft:-image.width*.5,marginTop:-image.height*.5,position:'absolute',left:'50%',top:'50%'}).fadeIn();
					var alt = img.attr('alt');
					if(typeof alt != 'undefined'){
						//$titleHolder.text(alt).fadeIn();
					}
				};
				image.src = img.attr('src');*/
				
			 });
			if(el.opt.autoplay){
				window.clearInterval(el.tID);
				autoplay();
			}
			function autoplay(){
					el.tID = window.setInterval(function(){
						var next = parseInt(el.index + 1);
						if((el.index + 1) == el.total){
							el.pagination.find('[href$=#0]').click();
							
						}
						else{
							el.pagination.find('[href$=#'+next+']').click();
						}	
					},7000)
			}
		});	
	}
SlideIS = {
		ease: 'easeInOutExpo',
		speed:1000,
		delay:null,
		autoplay:null,
		height: 321,
		width: 800,
		direction : 'vertical' // vertical horizontal
	};	
})(jQuery);

var SiteNav = {
		_over : function() {
			var el = $(this);
			if(el.find(".sub").size()>0){
				el.find(".sub").fadeTo('fast', 1).show();
				el.find(".link").addClass('current');
				Cufon.replace(el.find(".link"),{hover: true, fontFamily: 'Myriad Pro'});
			}
		},
		_out : function() {
			var el = $(this);
			if(el.find(".sub").size()>0){
				el.find(".sub").fadeTo('fast', 0, function() {
				  $(this).hide(); 
				el.find(".link").removeClass('current');
				  Cufon.replace(el.find(".link"),{hover: true, fontFamily: 'Myriad Pro'});
			  });
			}
		}
}
var AjaxM = {
    setAddress: function () {
        /*   $.address.init(function (event) {
        gui.dom.ajx.address();
        }).change(function (event) {
        
        var page = event.parameters.pid ? '/?' + event.queryString : event.path;
        alert(page)
        // Highlights the selected link
        gui.dom.ajx.click(function () {
        // $(this).removeClass('active');
        // if ($(this).attr('href') == (page == '/' ? '#' : '#!' + page)) {
        AjaxM.init($(this));
        //}

        });
        });*/

        gui.dom.ajx.click(function () {
            AjaxM.init($(this));


        })
    },
    init: function (el) {
        var el = $(el);

        el.parents('.nav').find('.nav-item').removeClass('active');
        el.parents('.nav-item').addClass('active');
        Cufon.replace(el.parents('.nav').find('.nav-item .link'), { hover: true, fontFamily: 'Myriad Pro' });
        var settings = {
            target: $('#target'),
            href: el.attr('href').replace("#!/", "")
        };

        var loading = $('#loading');

        loading.show();

        jQuery.ajax({
            url: settings.href,
            timeout: 20000,
            cache: true,
            beforeSend: function () {

            },
            success: function (data) {
                settings.target.html(data);
            },
            complete: function (data) {
                Cufon.replace(settings.target.find('.cf'), { hover: true, fontFamily: 'Myriad Pro' });
                loading.hide();
                //ow.hide();
            },
            error: function (msg) {
                loading.hide();
                //ow.hide();
            }
        });
    }

}
