$(document).ready(function() {

	//city select
	$('#city1').selectbox().bind('change', function(){ yer_getir(1); set_select('city2',$(this).val()); yer_getir(2);});
	$('#local1').selectbox().bind('change', function(){});
	$('#city2').selectbox().bind('change', function(){ yer_getir(2);});
	$('#local2').selectbox().bind('change', function(){});
	
	$('#tcity1').selectbox().bind('change', function(){ yer_getir2(1); set_select2('tcity2', $(this).val());});
	$('#tcity2').selectbox().bind('change', function(){ yer_getir2(2);});
	
	$('#pricetype').selectbox().bind('change', function(){});
	$('#distance1').selectbox({}).bind('change', function(){});
	$('#distance2').selectbox({}).bind('change', function(){});
	$('#age').selectbox({  className: 'jquery-selectbox'});
	
	$('#return').selectbox().bind('change', function(){ 
		if($(this).val()=="2"){$('#returndiv').show();}
		if($(this).val()=="1"){$('#returndiv').hide();}
	});
	
	//lang select
	$("#lang_activ_div").click(function () {
      $("#lang_cont").slideToggle();
	});
	$(document).bind('click', function(e) {
	  var trgt = e.target;
	  var currentListElements = jQuery('#lang_button').parent().parent().find('*').andSelf();
	  if(jQuery.inArray(trgt, currentListElements)<0 ) {$('#lang_cont').slideUp(); }	  
	});
	
	//tooltips
	$(".tooltip").tooltip({
		track: true,
		delay: 0,
		showURL: false,
		showBody: " - ",
		fade: 250
	});
	
	//fancy checkbox
	$('input[safari]:checkbox').checkbox({cls:'jquery-safari-checkbox'});
	
	//exchange
	$.getJSON(root+'php/infos.php?infos=exchange', {},
	function(jsonObj){
		$("#dollar").html(jsonObj[0]);
		$("#euro").html(jsonObj[2]);
	});	
	//weather
	$.getJSON(root+'php/infos.php?infos=weather&weather=TUXX0004', {},
	function(jsonObj){
		$("#wex img").attr("src",root+"php/weather/icons/"+jsonObj.image+".png");
		$("#weather").html(jsonObj.place+"<br/>"+jsonObj.degree);
		$('#wex img').ifixpng();
	});
	
	//preload
	jQuery.preloadImages = function(){
	  for(var i = 0; i<arguments.length; i++){
		jQuery("<img>").attr("src", arguments[i]);//.appendTo("body");
	  }
	};
	
	//pngfix
	$('#logo img').ifixpng();
	$('#wex').ifixpng();
	$('#wex img').ifixpng();
	$('#top').ifixpng();
	$('.slide').ifixpng();
	$('.boxs img').ifixpng();
	$('#tursab').ifixpng();
	
	//opacityfix
	function fix(id){
		var image = $(id).css("background-image");
		if (image.match(/^url\(["']?(.*\.png)["']?\)$/i)) { image = RegExp.$1;}
		$(id).css({
			'background-image': 'none',
			'filter': "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod="+
			($(this).css('background-repeat')=='no-repeat'?'crop':'scale')+", src='"+image+"')"
		});
	}
	$(function() {
	  if(jQuery.browser.msie){
		//fix("#carplease"); fix("#extraplease");	
	  }
	});
	
	$(window).scroll(function(){
		$(window).scrollTop(); 
	});
	
	
	news_slider();
	slideShow();
	
});

//News - developer: misima
news_current = 0;
news_heads	 = ".news_heads"
function news_slider() {
	$(news_heads).css({opacity: 0});
	$(news_heads+':first').css({opacity: 1});
	newssetint = setInterval('news_next()',8000);
}
function news_next() {
	news_old=news_current;news_current=news_current+1;news_current==$(news_heads).length?news_current=0:"";
	$(news_heads).eq(news_old).animate({opacity: 0.0}, 1000).removeClass('show');
	$(news_heads).eq(news_current).css({opacity: 0.0}).addClass('show').animate({opacity: 1.0}, 1000);
}

//Slide - developer: misima
gallery_current = 1;
gallery_old=0;
gallery_items = '.slide_image';
gallery_links = '#slide_menu a';

function slideShow() {
	$(gallery_items).fadeOut();
	$(gallery_items+':first').fadeIn();
	gallerysetint = setInterval('gallery_next()',6000);
	
}
function gallery_next() {
	
	gallery_capt = $(gallery_items).eq(gallery_current).find('img').attr('rel');	
	$(gallery_links).eq(gallery_old).removeClass('active');
	$(gallery_links).eq(gallery_current).addClass('active');
	$(gallery_items).eq(gallery_old).fadeOut();
	$(gallery_items).eq(gallery_current).fadeIn();
	gallery_old=gallery_current;
	gallery_current=gallery_current+1;
	gallery_current==$(gallery_items).length?gallery_current=0:"";
}
function gallery_nexter(a){
	if(a>$(gallery_items).length){}else{
	  clearInterval(gallerysetint);
	  gallery_current = (a-1);
	  gallery_next();
	}
};


//modalbox
var IE6 = false /*@cc_on || @_jscript_version < 5.7 @*/;
function modalBox(content, width, height, close) {
	if(close){
		$(content).append($('#ntz_modal div:first'));
		$('#ntz_modal').remove();
		$('#ntz_overlay').fadeOut(function(){$(this).remove();});
		try{if(IE6){$('body').find('select.unhideThis').removeClass('unhideThis').visibility('visible');}}catch(err){};
		$('embed.unhideThis, object.unhideThis').removeClass('unhideThis').css('visibility', 'visible');
		return false;
	}
	try{if(IE6){$('body').find('select:visible').addClass('unhideThis').visibility('hidden');}}catch(err){};
	$('embed:visible, object:visible').addClass('unhideThis').css('visibility', 'hidden');
	$('body').append('<div id="ntz_overlay"></div>');
	$('#ntz_overlay').click(function(){modalBox(content, '', '', true)});
	$('#ntz_overlay').css({
		width		:	'100%',
		height		:	$(document).height(),
		position	:	'absolute',
		left		:	0,
		top		:	0,
		backgroundColor	:	'#000',
		zIndex		:	100,
		opacity		:	0
	}).fadeTo(200, 0.5);
	$('body').append('<div id="ntz_modal"></div>');
	$('#ntz_modal').css({
		//border		:	'1px solid #2d7abb',
		width		:	width ? width : 350,
		//backgroundColor	:	'#FFFFFF',
		position	:	'absolute',
		left		:	'50%',
		top		:	$(document).scrollTop(),
		zIndex		:	101,
		marginLeft	:	-(Math.ceil((width ? width : 800)/2)),
		marginTop	:	Math.ceil(($(window).height()-height)/2)
	}).append($(content+' div:first')).show("drop",{direction:'up'},500).draggable();;
	//$('#ntz_modal a:eq(0), #ntz_modal input, #ntz_modal textarea').focus();
	try{
		callback.call();
	}catch(err){};	
	$(document).bind('scroll', function(){
		$('#ntz_modal').css({
			top:$(document).scrollTop()
		});
	});
};
