﻿function ToggleAppear(item)
{
	if (selector = $('div#' + item))	
	{
		$(selector).toggle();
	};
}

function ToggleOnlyAppear(item)
{
	if (selector = $('div#' + item))	
	{
		//$(selector).show()
		$(selector).fadeIn()
		if (item == "subscriptionForm"){
			$('input#ContactName').focus();
			$('#subscriptionFormResult').hide();
			//$.scrollTo('subscriptionForm', 800);
		}
		
	};
}

function ToggleOnlyDisappear(item)
{
	if (selector = $('div#' + item))	
	{
		//$(selector).hide()
		$(selector).fadeOut()
	};
}

function setupLabel() {
	if ($('.label_check input').length) {
		$('.label_check').each(function(){ 
			$(this).removeClass('c_on');
		});
		$('.label_check input:checked').each(function(){ 
			$(this).parent('label').addClass('c_on');
		});                
	};
	if ($('.label_radio input').length) {
		$('.label_radio').each(function(){ 
			$(this).removeClass('r_on');
		});
		$('.label_radio input:checked').each(function(){ 
			$(this).parent('label').addClass('r_on');
		});
	};
};

function initialize() {
    var myOptions = {
        zoom: 14,
        center: new google.maps.LatLng(41.006724, 28.806527),
        mapTypeId: google.maps.MapTypeId.ROADMAP
    }
    var map = new google.maps.Map(document.getElementById("map_canvas"),
                                  myOptions);

    var image = 'http://www.onurmarket.net/images/icons/marker.png';
    var infowindow = new google.maps.InfoWindow({
        content: '<strong>Genel Müdürlük</strong>',
        maxWidth: 200
    });
    var myLatLng = new google.maps.LatLng(41.006724, 28.806527);
    var marker = new google.maps.Marker({
        position: myLatLng,
        map: map,
        icon: image
    });

    google.maps.event.addListener(marker, 'click', function () {
        infowindow.open(map, marker);
    });
    
}

$(document).ready(function() {
	$('a.external').attr('target', '_blank');
	$("a[rel='external']").attr('target','_blank');
	
	//highlights the current in a menu by comparing the links to the current URL path
    var links = $("#nav > ul > li > a");
	
    links.each(function () {
		var linkToFirstChild = $(this).parent().find("> ul > li > a").attr("href");
		$(this).attr("href", linkToFirstChild);
        //if (window.location.pathname.indexOf($(this).attr("href")) != -1) {
        //    $(this).parent().addClass("current");
        //}
    });
	
	
	
	if ($("#map_canvas").length) {
        initialize();
    }
	
	var breadcrumbLink = $("#nav > ul > li.current > a").attr("href");
	//alert(breadcrumbLink);
	$(".breadcrumb > span > a").attr("href", breadcrumbLink);
	
	$('body').addClass('has-js');
	$('.label_check, .label_radio').click(function(){
		setupLabel();
	});
	setupLabel();
	
	$('#fancy_img').wrap('<a href="http://www.facebook.com/onurmarketler" target="_blank" />')
	
	$('#SearchSoreForm #LocalityID, #SearchSoreForm #DistrictID').selectmenu({
		style:'popup', 
		maxHeight: 150,
	});
	
	$("form#CustomerFormSelectionForm").submit(function() {
		
		CustomerFormSelection = $('#CustomerFormSelection').val();
		location.href = CustomerFormSelection;
		return false;
	}); 
	$("form#wearehereforyou").submit(function() {
		location.href = $('input[name=wearehereforyouoption]:checked').val();
		return false;
	});
	
	$("form#CorporateFormSelectionForm").submit(function() {
		
		CorporateFormSelection = $('#CorporateFormSelection').val();
		location.href = CorporateFormSelection;
		return false;
	});
	
});


jQuery(function() {
	
	/*var v = jQuery("#Newsletter-Form").validate({
		submitHandler: function(form) {
			$('#Newsletter-Form-Process').show();
			jQuery(form).ajaxSubmit({
				url:        '/DoSubscribe', 
				success:    function() { 
					 $('#Newsletter-Form-Process').hide();
					 $('#subscriptionForm').hide();
					 $('#subscriptionFormResult').show();
					 v.resetForm();
				} 
			});
		}
	});
	*/
	jQuery("#NeedsMail2").click(function(){
		$(this).parents('ul:eq(0)').find(':checkbox').attr('checked', this.checked);
	});
	
	jQuery("#reset").click(function() {
		v.resetForm();
	});
	
	$(".fancybox").fancybox({
		hideOnContentClick     : false
	});
	
	$("a#btn-splash").fancybox({
		hideOnContentClick     : false
	});
	
	if (!($.cookie('IsFirstVisit')==='false')) {
		$("#btn-splash").trigger('click');
		$.cookie('IsFirstVisit', 'false', { expires: 1 });
	}
	
	$(".logo a").click(function(){
		$.cookie('IsFirstVisit', 'true');
	});
	
	//$('#header h1.logo').click(function (){
	//	$.cookie('IsFirstVisit', null);
	//});
	
});

// Timeline
$(function(){
	if ($('#timeline').length) {
	$().timelinr({
		autoPlay: 'true',
		autoPlayPause: 5000,
		startAt: 1
	})
	}
});

