 $('.print').click(function(){  
	window.print();
});

//Slider function
function slideSwitch() {
    var $active = $('#slideshow img.active'); // select the active image
	
    if ( $active.length == 0 ) {
        $active = $('#slideshow img:last'); // if there is no active image then it sets the last image to the last
    }

    var $next =  $active.next('img').length ? $active.next('img')
    : $('#slideshow img:first');

    $('#slideshow span').text($next.attr("alt")); //ads the alt text to the span tag
		
    $active.addClass('last-active'); //ads the last-active class to the last slided img
	
	
    $next.css({
        opacity: 0.0
    })
    .addClass('active')
    .animate({
        opacity: 1.0
    }, 1000, function() {
        $active.removeClass('active last-active');
        $('#slideshow span').text(null);
    });

}
$(function() {
	//event tracking
	 $('a').click(function () {
		_gaq.push(['_trackEvent', 'links', $(this).attr("href")]);
	});


    //shadow
    $("div#pMain").wrap("<div class=\"shadow_w925\"></div>");
	$(".lightbox").prettyPhoto();
    //calling the jqTransform function
    $('form').jqTransform();

    //left sidebar accordation
    //Matches all the elements that are not the first one and hides them
	if ( $("div#leftSidebar ul.active") == 'undefined' ) {
	    $("div#leftSidebar h2:not(:first)").next().hide();
		$("div#leftSidebar h2:first").next("ul").addClass('active');
	}
	else {
		$("div#leftSidebar ul:not(.active)").hide();
	}
    $("div#leftSidebar h2").click(function(){
        $(this).removeClass("active");
        $(this).next("ul").addClass("active");

        $("div#leftSidebar ul").slideUp("medium");
        //slides up the given element
        $(this).next().slideDown("medium");
        //makes the next element slidedown, so the next .slider
        return false;
    });
	
	if ( $("div.sliderContent.active") == 'undefined' ) {
	    $("h2.slider").next().hide();
		$("h2.slider:first").next("div.sliderContent").addClass('active');
	}
	
	$("h2.slider").click(function(){
		$(this).next("div.sliderContent").slideToggle("medium");
	});


    //lang select class
    $("ul.SelectUl").addClass("select");
    //initialing the prettyphoto plugin
	
    //slideshow
	
	if($('#slideshow').length > 0) {
		var alt = $('#slideshow img.active').attr("alt");
        $("#slideshow").append("<span class=\"pngfix\">" + alt + "</span>");
		setInterval( "slideSwitch()", 5000 );//5000ms = 5sec
    }

	/* ie6 hack */
	if ($.browser.msie == true) {
		if ($.browser.version < 7 ) {
			$('div#pContent').append('<div class="update">Az ön böngészője elavult.<br/>Kérjük frissítse böngészője verzióját vagy használjon egy másikat.<br style="display: block; height: 10px; width: 10px;"/><a href="http://www.mozilla-europe.org/hu/firefox/" target="_blank">Firefox</a> / <a href="http://www.google.com/chrome" target="_blank">Chrome</a></div>');
		}
	}
	
    /* Ajax mail sending */
	
	$('form#contactus_form #send').click(function() {
		$('#pContent').append('<span class="loading">Email küldése</span>');
		
		var name = $('input#contactus_name').val();
		var email = $('input#contactus_email').val();
		var address = $('input#contactus_address').val();
		var phone = $('input#contactus_phone').val();
		var subject = $('input#contactus_subject').val();
		var message = $('textarea#contactus_message').val();
		
		var sample = $('input#contactus_sample').attr('checked'); 
		
		$.ajax({
			url: '/magunkrol/kapcsolat/mailprocess.php',
			type: 'POST',
			data: 'name=' + name + '&mailprocess=true&email=' + email + '&address=' + address + '&phone=' + phone + '&subject=' + subject + '&message=' + message + '&sample=' + sample,

			success: function(result) {
				$('.response').remove();
				$('#pContent').append('<div class="response">' + result + '</p>');
				$('.loading').fadeOut(500, function() {
					$(this).remove();
				});
			}
		});			
		return false;
	});

	
    /* Google Maps */
	//defining initial variables
	if($('#gmap_canvas').length > 0) {
		gMap();
	}
	function gMap() {
		var map, lastI;
		var BoundsArray = [];
		//initial settings of the map
		var myOptions = {
			zoom: 15,
			center: new google.maps.LatLng(47.498343, 19.040508),
			mapTypeId: google.maps.MapTypeId.ROADMAP,
			mapTypeControl: false,
			scaleControl: false,
			scrollwheel: false,
			navigationControlOptions: {
				style: google.maps.NavigationControlStyle.SMALL
			}
		};
		
		//loading in the map, based on the myOption setting
		map = new google.maps.Map(document.getElementById("gmap_canvas"), myOptions);

		$.ajax({
			type: "GET",
			url: "/xml/markers.xml",
			dataType: "xml",
			success: parseXml
		}); // close ajax

		// iterating throw the xml markers
		function parseXml(xml){
			var i = 0;
			
			$(xml).find(xmlTag).each(function(){
				var markerLtd = parseFloat($(this).find("latitude").text());
				var markerLng = parseFloat($(this).find("longitude").text());
				var markerTitle = $(this).find("title").text();
				var markerAddress = $(this).find("address").text();
				var markerPhone = $(this).find("phone").text();
				var markerUrl = $(this).find("url").text();
					if (markerUrl.length > 0) { 
						var url = "<br/><a href=\"http://" + markerUrl + "\" target=\"_blank\">www." + markerUrl + "</a><br/>"; 
					}
					else {
						var url = "<br/>";
					}
				var markerOpeningHours = $(this).find("opening_hours").text();
				BoundsArray[i] = new Object;

				// Create the marker...
				var marker = new google.maps.Marker({
					position: new google.maps.LatLng(markerLtd, markerLng),
					map: map,
					title: markerTitle,
					icon: 'http://img.livingstones.hu/gmaps/lsmarker.png' //37x32
				}); //marker() close

				
				BoundsArray[i].marker = marker;
				BoundsArray[i].html = "<span class=\"bold\">" + markerTitle + "</span><br/>" + markerAddress + "<br/>" + markerPhone + url + markerOpeningHours;

				// Create the infoWindow...
				BoundsArray[i].infoWindow = new google.maps.InfoWindow({
					content: BoundsArray[i].html
				});

				// Create the listener with a closure...
				BoundsArray[i].listener = makeClosure(i, BoundsArray[i].marker);

				//adding the coordinates to the markers list
				$("<li />").html(marker.title).click(function(){
					map.panTo(marker.position);
				}).appendTo("#gmap_markerslist");
				
				//adding the coordinates to the markers list
				$("<li />").html(BoundsArray[i].html).click(function(){
					map.panTo(marker.position);
					
				}).appendTo("#distributorList");
				
				i++;
			}); // iteration close
		}

		// Make a simple closure with the listener...
		function makeClosure(i, marker )
		{
			var listener = google.maps.event.addListener(marker, 'click', function() {
				openInfoWindow(i);		// necessary to open the infowindow
			});
			return listener;
		}

		// Open the infoWindow - called from the closure...
		function openInfoWindow(i)
		{
			if ( typeof(lastI) == 'number' && typeof(BoundsArray[lastI].infoWindow) == 'object' )
			{
				BoundsArray[lastI].infoWindow.close();
			}
			lastI = i;
			BoundsArray[i].infoWindow.open(map,BoundsArray[i].marker);
		}
	}
		
}); // dom read closing
