$(document).ready(function() {

	$(".mask-date").keyfilter(/[\d0-9\-]/);

    $("a.fancy").fancybox({
        'overlayOpacity'        : 0.7,          //Opacity of the overlay (from 0 to 1; default - 0.3)
        'overlayColor'          : '#000',       //Color of the overlay
        'titleShow'             : false         //Toggle title
    });

	$(".printlink").click(function() {

		printElem({
			overrideElementCSS:[{ href:'http://audi.hu.ws/css/styles_print.css' }],
			eaveOpen:true,
			printMode:'popup',
			printBodyOptions: { styleToAdd:'color: #000; line-height: 16px; background: transparent url(/gfx/print/bg_print.gif) no-repeat right top; font-family: Verdana; font-size: 10px; padding-top: 50px;' }
		});

		return false;
	});

	$('.data a.mailto').each(function(el) {
		var email = $(this).attr('href');
		$(this).attr('href', 'mailto:'+email);
	});


    $('select.fixed-select-css').ieSelectWidth
    ({
        containerClassName : 'select-container',
        overlayClassName : 'select-overlay'
    });


// gyorsmenu

    $(".tip").tooltip({position: 'bottom left'});

	$.tools.tooltip.addEffect("toggle",

		function(done) {
			var conf = this.getConf(), tip = this.getTip(), o = conf.opacity;
			var leftP = parseInt(tip.css('left')) + 350  + 'px'

			$('a.gyorsmenu').addClass('gyorsmenu_active')
			$('a.gyorsmenu_de').addClass('gyorsmenu_de_active')
			$('a.gyorsmenu_en').addClass('gyorsmenu_en_active')

			if (o < 1) { tip.css({opacity: o}); }
			tip.css({top: '106px', left: leftP});

			tip.show();
			done.call();
		},

		function(done) {
			$('a.gyorsmenu').removeClass('gyorsmenu_active')
			$('a.gyorsmenu_de').removeClass('gyorsmenu_de_active')
			$('a.gyorsmenu_en').removeClass('gyorsmenu_en_active')
			this.getTip().hide();
			done.call();
		}
	);

// főoldali menü

    $("ul.topnav li").hover(
        function(){ $("ul", this).slideDown("fast").show(); $("a.main", this).css({'background-position': 'bottom left'}); },
        function() { $("ul", this).stop(true, true).slideDown(); $("ul", this).hide(); $("a.main", this).css({'background-position': 'top left'}); }
    );
});

    var __lang = '<{$_arg.0}>';
    var audi = {src: '/gfx/audi_type.swf'};
    sIFR.activate(audi);
    sIFR.replace(audi, {
        selector: 'h1.title'
        ,wmode: 'transparent'
        ,css: {
            '.sIFR-root': { 'color': '#ffffff', 'background-color': 'none', 'margin-bottom': '0' }
        }
    });
    sIFR.replace(audi, {
        selector: 'h1.sub'
        ,wmode: 'transparent'
        ,css: {
            '.sIFR-root': { 'color': '#2B2F33', 'background-color': 'none', 'margin-top': '0' }
        }
    });
    sIFR.replace(audi, {
        selector: 'h2'
        ,wmode: 'transparent'
        ,css: {
            '.sIFR-root': { 'color': '#ffffff', 'background-color': 'none', 'margin': '0', 'padding': '0', 'font-size': '14px' }
        }
    });
    sIFR.replace(audi, {
        selector: 'h3'
        ,wmode: 'transparent'
        ,css: {
            '.sIFR-root': { 'color': '#ffffff', 'background-color': 'none', 'margin': '0', 'padding': '0', 'font-size': '11px', 'float': 'left' }
        }
    });
    sIFR.replace(audi, {
        selector: 'h4'
        ,wmode: 'transparent'
        ,css: {
            '.sIFR-root': { 'color': '#ff0000', 'background-color': 'none', 'margin': '0', 'padding': '0', 'font-size': '11px', 'float': 'left' }
        }
    });


function printElem(options){
	$('._print').printElement(options);
}

/*
 * Gyárlátogatás
 */
function changeType( selected ) {
    if ( id1 == selected.id ) {
        $('#type_1').show();
        $('#type_2').hide();
        $('#type_3').hide();
    } else if ( id2 == selected.id ) {
        $('#type_1').hide();
        $('#type_2').show();
        $('#type_3').hide();
    } else if ( id3 == selected.id ) {
        $('#type_1').hide();
        $('#type_2').hide();
        $('#type_3').show();
    }
}

function update1Selected(date) {
	jQuery('#date1_year').val(date.substring(0, 4));
	jQuery('#date1_month').val(date.substring(5, 7));
	jQuery('#date1_day').val(date.substring(8, 10));
}

function update2Selected(date) {
	jQuery('#date2_year').val(date.substring(0, 4));
	jQuery('#date2_month').val(date.substring(5, 7));
	jQuery('#date2_day').val(date.substring(8, 10));
}

function update3Selected(date) {
	jQuery('#date3_year').val(date.substring(0, 4));
	jQuery('#date3_month').val(date.substring(5, 7));
	jQuery('#date3_day').val(date.substring(8, 10));
}

//Filmek videovaltas
function changeVideo(item) {
	if ( item.id != active_video && active_video != '' ) {
		sotetit(active_video);
	} else if ( active_video != '' ){ return false; }
	active_video = item.id;
	var id = item.id.substr(6);
	$.post('/'+__lang+'/ajax/changeVideo/'+id+'/',
	function(data){
		$('#mateplayer')[0].newVideo(_video_host+'vgallery/'+data);
	});
}



// Galéria kepvaltas
var run = 0;
function changeImage(img) {
	if ( run == 1) return false;
	run = 1;
	var old_img = active_img;
	if ( img.id != active_img && active_img != '' ) {
		sotetit(active_img);
	} else if ( active_img != '' ){ return false; }
	active_img = img.id;
	var img_id = img.id;

	$("#big_"+old_img).fadeOut(200, function () {
		$("#big_"+img_id).fadeIn(500, function() { run = 0; } );
	});
}

function sleep(sleep) {
	var start = new Date().getTime();
    while ( new Date().getTime() < start+sleep );
}

//opacity
function sotetit(id) {
	document.getElementById(id).style.opacity=0.4;
	if ( document.getElementById(id).filters )	{
		document.getElementById(id).filters.alpha.opacity=40
	}
}

function vilagosit(id) {
	document.getElementById(id).style.opacity=1;
	if ( document.getElementById(id).filters ) {
		document.getElementById(id).filters.alpha.opacity=100
	}

}

function downloadImage(img) {
    var img = (typeof(img) == 'object') ? img.src : img;
    img = img.replace("/tn2", "");
    img = img.replace("http://audi.hu.ws", "").replace("http://audi.webshark.ws", "").replace("http://audi.hu", "");
    img = encodeURIComponent(img);
    img = Base64.encode(img);
    window.location="/"+__lang+"/ajax/downloadImage/"+img+"/"
}

/*
 * Gyárlátogatás
 */
function rules(id) {
	if ( jQuery('#'+id).attr('checked') == true ) {
		jQuery('div.urlap').show();
	} else {
		jQuery('div.urlap').hide();
	}
}

function setDates(id, date){
	jQuery('#visitors').hide();
	if ( jQuery('#'+id).val() == 0) {
		jQuery('#dates').hide();
	} else {
		jQuery('#dates').show();
		jQuery.ajax({
			'url': '/'+__lang+'/ajax/setcalendar/'+jQuery('#'+id).val()+'/'+date+'/',
			'success': function (data) {
				jQuery('#dates').html(data);
				if ( date && date != 'undefined') {
					setVisit( date, 'fp_gyarlatogatas_lang' );
				}
			}
		});
	}
}

function setVisit(date, lang) {
	jQuery('#visitors').show();
	jQuery.ajax({
		'url': '/'+__lang+'/ajax/setvisit/'+date+'/'+jQuery('#'+lang).val()+'/',
		'success': function (data) {
			jQuery('#times').html(data);
		}
	});
}

function fakeGet() {
	setTimeout( "jQuery.ajax({ 'url': '/'+_lang+'/', 'success': function (data) { fakeGet(); } });", 60000);
}

