
$(function(){
	
	<!-- cufon ie6da disable ettim (mali)-->
  	if (jQuery.browser.msie && jQuery.browser.version.substr(0,1)<=6) {
		//ie6
	} else {
  		Cufon.replace('nav ul li a, div#slider_text h2, .promo h3, .slogan, #pagetitle h1, div.list ul li h3, #slider_text p, span.intro, .article h2, .article h3', {hover:true, fontFamily: 'Segoe UI'});
	}
  	Cufon.now();

	// Create an array of images that you'd like to use
    var images = [
        "/images/bg01.jpg",
        "/images/bg02.jpg",
		"/images/bg03.jpg",
		"/images/bg04.jpg"
    ];
	
	var hidden = $('body').append('<div id="img-cache" style="display:none/>').children('#img-cache');
	$.each(images, function (i, val) {
	  $('<img/>').attr('src', val).appendTo(hidden);
	});
	
    var index = 0;
    $.backstretch(images[index], {speed: 500});
    setInterval(function() {
					index = (index >= images.length - 1) ? 0 : index + 1;
					$.backstretch(images[index]);
				}, 9000);
	
	$("#slider_img").easySlider({
				auto: true, 
				continuous: true,
				speed: 800,
				pause: 7000,
				numeric: true
			});
			
	$("#slider_gallery").easySlider({
		auto: true, 
		continuous: true,
		speed: 800,
		pause: 7000,
		numeric: false
	});
	
	
	
	
	/* This is basic - uses default settings */
    $(".article_image a").fancybox();
	$("a.fancybox").fancybox();

    /* Using custom settings */
    $("a#inline").fancybox({
        'hideOnContentClick': true
    });

    /* Apply fancybox to multiple items */
    $("a.gallery").fancybox({
        'transitionIn': 'elastic',
        'transitionOut': 'elastic',
        'speedIn': 600,
        'speedOut': 200,
        'overlayShow': false
    });

    $("a.videolink").fancybox({
        frameWidth: 480,
        frameHeight: 295,
        overlayShow: true,
        overlayOpacity: 0.78
    });
	
	$(".modalContainer").dialog({
		modal: true,
		autoOpen: false,
		width:575,
		height:'auto'
	});
	
	
	$("#select_map").change(function(){
		//hide all maps
		$(".map_container a").addClass("hidden");
		
		$(".map_container a#map" + $(this).val()).removeClass("hidden");
	});	
	
	$("#select_map").change();
});

function fSearch(){
	$("#q").val($("#search").val() + " site:ozsoygroup.com");
	document.frmSearch.submit(); 	
}

function onEnterSearch(evt){
	var keyCode = null;
	if(evt.which) {
		keyCode = evt.which;
	} else if(evt.keyCode) {
		keyCode = evt.keyCode;
	}
	if(13 == keyCode) {
		fSearch();
		return false;
	}
	return true;
}
			
function contactRequest() {
		
	var o;
	
	$("#contactForm .success").addClass("hidden");
	$("#contactForm .error").addClass("hidden");
	
	o = $("#contactForm #topic");
	if (parseInt(o.val()) == 0) {
		o.prevAll("label:first").addClass("error"); o.nextAll("em:first").show(); $(".ui-state-error").show();
		o.focus();
		return;
	}
	else {
		o.prevAll("label:first").removeClass("error"); o.nextAll("em:first").hide(); $(".ui-state-error").hide();
	}
	
	o = $("#contactForm #name");
	if ($.trim(o.val()).length == 0) {
		o.prevAll("label:first").addClass("error"); o.nextAll("em:first").show(); $(".ui-state-error").show();
		o.focus();
		return;
	}
	else {
		o.prevAll("label:first").removeClass("error"); o.nextAll("em:first").hide(); $(".ui-state-error").hide();
	}
	
	o = $("#contactForm #email");
	if ($.trim(o.val()).length == 0) {
		o.prevAll("label:first").addClass("error"); o.nextAll("em:first").show(); $(".ui-state-error").show();
		o.focus();
		return;
	}
	else {
		o.prevAll("label:first").removeClass("error"); o.nextAll("em:first").hide(); $(".ui-state-error").hide();
	}
	
	var re = new RegExp("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$");
	var m = re.exec(o.val());
	if (m == null) {
		o.prevAll("label:first").addClass("error"); o.nextAll("em:first").show(); $(".ui-state-error").show();
		o.focus();
		return;
	}
	else {
		o.prevAll("label:first").removeClass("error"); o.nextAll("em:first").hide(); $(".ui-state-error").hide();
	}
	
	o = $("#contactForm #gsm");
	if ($.trim(o.val()).length == 0) {
		o.prevAll("label:first").addClass("error"); o.nextAll("em:first").show(); $(".ui-state-error").show();
		o.focus();
		return;
	}
	else {
		o.prevAll("label:first").removeClass("error"); o.nextAll("em:first").hide(); $(".ui-state-error").hide();
	}
	
	o = $("#contactForm #message");
	if ($.trim(o.val()).length == 0) {
		o.prevAll("label:first").addClass("error"); o.nextAll("em:first").show(); $(".ui-state-error").show();
		o.focus();
		return;
	}
	else {
		o.prevAll("label:first").removeClass("error"); o.nextAll("em:first").hide(); $(".ui-state-error").hide();
	}
	
	$("#contactForm .loader_sm").removeClass("hidden");
	
	$.ajax
	({
		type: "POST",
		url: "/lib/ajax/contactform_send.php",
		data: $("#contactForm").serialize(),
		success: function (ret) {

			if (ret == "true") {
				
				$("#contactForm #topic").val("0");
				$("#contactForm #name").val("");
				$("#contactForm #email").val("");
				$("#contactForm #gsm").val("");
				$("#contactForm #message").val("");
				
				$("#contactForm .success").removeClass("hidden");
				$("#contactForm .loader_sm").addClass("hidden");
			}
			else {
				$("#contactForm .error").removeClass("hidden");
				$("#contactForm .loader_sm").addClass("hidden");
			}
		},
		error: function (ret) {
			error.setmessage(ret);
		}
	});
}
