/*
*	h.js
*
*	Javascript Development madebycat®
* 	http://www.madebycat.com
*
*	Dual licensed under the MIT (MIT-LICENSE.txt)
*	and GPL (GPL-LICENSE.txt) licenses.
*
*	fercomotor
*/

	var fercomotor = {
		load:function(){
			
            
            //Leftmenu	{
			$(".left-nav ul li a[href*=void]").removeAttr("onclick").click(function(){
				if($(this).parent("li").children("ul").length != 0){
					$(this).parent("li").children("ul").slideToggle(500);
					return false;
				}
			});
		
			if($("ul").is(".idTabs")){
				$(".idTabs li:first").addClass("active");
				$(".idTabs li:first a").addClass("selected");
				$($(".idTabs li.active a").attr('to')).show();
				$(".idTabs li a").click(function(){
					$(".idTabs li").removeClass('active');
					$(this).parent("li").addClass('active');
					$(".tab-content").hide();
					$($(this).attr('to')).show();
					return false;
				});
			};
			//Leftmenu }
			
			//Tabs {
			$("#spec-tabs ul#spec-tab-links li").each(function(i){
				$(this).attr("tabs", "tab"+i);
			});
			$(".spec-tab").each(function(i){
				$(this).attr("tabs", "text-tab"+i);
				$(this).attr("open", "closed");
			});
			$("#spec-tabs ul#spec-tab-links li:first").addClass("active");
			$(".spec-tab[tabs=text-tab0]").css("display", "block").attr("open", "open");
			setTimeout('$(".tabs-text").height($(".spec-tab[open=open]").height())', 500);
			$("#spec-tabs ul#spec-tab-links li a").click(function() {
				$("#spec-tabs ul#spec-tab-links li").removeClass("active");
				$(this).parent().addClass("active");
				tabId = "text-" + $(this).parent().attr("tabs");
				$(".spec-tab[open=open]").fadeOut(300, function() {
					$(".spec-tab[tabs=" + tabId +"]").slideDown();
					$(".spec-tab").attr("open", "closed");
					$(".spec-tab[tabs=" + tabId +"]").attr("open", "open");
					//needs animation
					setTimeout('$(".tabs-text").height($(".spec-tab[open=open]").height())', 500);
					});
					
				return false;
				
			})
			//Tabs }
			
			//Gallery{
			if(!$("#gallery").is(":hidden")){
				$("#gallery img:first").addClass("active");
				$("#gallery").append('<div class="gallery-pager"><ul></ul></div>');
				var pageSize = $("#gallery img").size();
				if(pageSize > 1 ){
					$("#gallery img").each(function(i){
						$("#gallery .gallery-pager ul").append("<li><a href='#'><span>" + (i + 1) + "</span></a></li>")
					});	
				};
				$("#gallery ul li:first").addClass("active");
			}
			$("#gallery ul li a").click(function(){
				if($(this).parent("li").hasClass("active")){
					return false;
				}
				else{
					if(!$("#gallery img").is(":animated")){
						var activeImg = $("#gallery ul li a").index($(this));
						$("#gallery ul li.active").removeClass("active");
						$("#gallery ul li").eq(activeImg).addClass("active");
						$("#gallery img.active").fadeOut(300,function(){
							$(this).removeClass("active");
							$("#gallery img").eq(activeImg).fadeIn(300,function(){
								$(this).addClass("active");
							});
						});
					}
					return false;
				}
			});
			//Gallery }

			//PGallery {
			if(!$("#pgallery").is(":hidden")){
					$("#pgallery img:first").addClass("active").css("display","block");
					$("#pgallery ul li:first").addClass("active");
				}
				
				$("#pgallery ul li a").click(function(){
					if($(this).parent("li").hasClass("active")){
						return false;
					}
					else{
						if(!$("#pgallery img").is(":animated")){
							var activeImg = $("#pgallery ul li a").index($(this));
							$("#pgallery ul li.active").removeClass("active");
							$("#pgallery ul li").eq(activeImg).addClass("active");
							
							$("#pgallery img.active").fadeOut(300,function(){
								$(this).removeClass("active");
								$("#pgallery img").eq(activeImg).fadeIn(300,function(){
									$(this).addClass("active");
								});
							});
						}
						return false;
					}
				});
			//PGallery }
			
			//Table {
			$(".table tr:even").addClass("even");
			//Table }
			/*
			//marka-logo:hover {
			$('#marka-nav ul li').mouseenter(function(){
				artID = $(this).attr("id");
				if (artID == "article_34"){
					$("#marka-vespa").fadeIn(200);
				}else if (artID == "article_35"){
					$("#marka-piaggio").fadeIn(200);
				}else if (artID == "article_76"){
					$("#marka-gilera").fadeIn(200);
				}else if (artID == "article_80"){
					$("#marka-aprilia").fadeIn(200);
				}else if (artID == "article_101"){
					$("#marka-moto-guzzi").fadeIn(200);
				}else if (artID == "article_102"){
					$("#marka-derbi").fadeIn(200);
				}
			}).mouseleave(function() {
				$("#marka-logos div").fadeOut(400);
			});
			//marka-logo:hover }
			*/
			//aksesuar {	
			$(".aks-img img").each(function() {
				//$(this).parent().width($(this).width());
				//tmargin = (240 - $(this).height())/2;
				//$(this).css("margin-top", tmargin+"px");
				$(this).parent().css("background","url(" + $(this).attr("src") +") no-repeat center center").children("img").css("display","none");
			});
			//aksesuar }
			
			//prettyPhoto {
			$("#pgallery a[rel^='prettyPhoto']").prettyPhoto({theme:'light_rounded'});
			//$("#pgallery a.prettyphoto-link:first").css("display", "block");
			$("#opts-photo-gallery a").click(function(){
				$("#pgallery a:first").trigger("click")
				return false;
			});
			$("#spec-photo-gal a").click(function(){
				$("#pgallery a:first").trigger("click")
				return false;
			});
			$("#photo-galerie a").click(function(){
				$("#pgallery a:first").trigger("click")
				return false;
			});
			//prettyPhoto }
			
			
			/*
			$("#btn-kaydet").click(function(){
				etext = $(this).parent().parent().find("div#EMAIL").val();
				locationID = $(".ebulten-btn").parent().attr("action");
				location.href = locationID+"?EMAIL="+etext
				return false;
			})
		
			if ($get("EMAIL") != "") {
				$("#FORM-INPUT-EMAIL").val($get("EMAIL"))
			};
			*/


			
			
		},
		
		resize:function(){
			
		},
		
		Cufonsle:function(){
			Cufon.replace(['.left-nav ul li a'], {fontFamily: 'diavlo',hover:true});
			Cufon.replace(['#spec-tabs ul li a'], {fontFamily: 'diavlo',hover:true});
			Cufon.replace(['#breadcrumb ul li'], {fontFamily: 'diavlo',hover:true});
			Cufon.replace(['#main-nav ul li a'], {fontFamily: 'diavlo',hover:true});
			Cufon.replace(['#footer-nav ul li a'], {fontFamily: 'diavlo',hover:true});
			Cufon.replace(['.inner-content h1'], {fontFamily: 'diavlo',hover:false});
			Cufon.replace(['.inner-content h2'], {fontFamily: 'diavlo',hover:false});
			Cufon.replace(['.gateway h3'], {fontFamily: 'diavlo',hover:false});
			Cufon.replace(['#marka-nav ul li a'], {fontFamily: 'conduit',hover:true});
			Cufon.replace(['.credits form label'], {fontFamily: 'diavlo',hover:true});
			Cufon.replace(['.aks p a'], {fontFamily: 'diavlo',hover:true});
			//Cufon.replace(['.credits span'], {fontFamily: 'diavlo',hover:true});
			Cufon.replace(['.gtype-1-text *'], {fontFamily: 'diavlo',hover:true});
			Cufon.replace(['.newsletter label'], {fontFamily: 'diavlo',hover:true});
			Cufon.replace(['.newsletter .more'], {fontFamily: 'diavlo',hover:true});
			Cufon.replace(['#headline h1'], {fontFamily: 'diavlo',hover:true});
			Cufon.replace(['.opts-list ul li a'], {fontFamily: 'diavlo',hover:true});
			Cufon.replace(['.middle-text p'], {fontFamily: 'diavlo',hover:false});
			Cufon.replace(['.s-fiyat'], {fontFamily: 'conduit',hover:true}); 
			//Cufon.replace(['.aksesuar-item *'], {fontFamily: 'helvetica',hover:true});			
		}
		
	};
	
$(window).resize(function() {
	fercomotor.resize();
});

$(document).ready(function(){
	
	$(".overlay").css("height",$(document).height());
	$(".overlay").css("width",$(document).width());
	$(".overlay,.splash-close").click(function(){
		 setTimeout(function(){ $('.splash-box').slideUp('slow'); }, 200);
		 setTimeout(function(){ $(".overlay").detach(); }, 900);
		return false;
	});
	
	
	$(".overlay").live("click",function(){
		setTimeout(function(){ $('.splash-box').slideUp('slow'); }, 200);
		setTimeout(function(){ $(".overlay").detach(); }, 900);
		return false;
	});
	
	$(".splash-close").live("click",function(){
		setTimeout(function(){ $('.splash-box').slideUp('slow'); }, 200);
		setTimeout(function(){ $(".overlay").detach(); }, 900);
		return false;
	});
	fercomotor.load();
	fercomotor.Cufonsle();
	
	/**/
	var video;
	/*
	if($("#altmisinciyil").children("iframe").length == 0){
		$("#spec-video").hide();
	}
	else{
		video = $("#altmisinciyil").html();
	}
	*/
	$("li#spec-video a").click(function(){
		$("body").append('<div id="splash"></div>');
		$("#splash").css("opacity","0.5");
		
		if($.browser.msie && $.browser.version == "6.0"){
			$("#splash").css("height",$(document).height());
		};
		$("#altmisinciyil").html(video);
		$("div.videoContainer").show();
		return false;
	});
	
	$(".videoContainer a.videoClose").click(function(){
		$("#splash").detach();
		$("div.videoContainer").hide();
		$("#altmisinciyil").empty();
		return false;
	});
	
	$("#splash").live("click",function(){
		$("#splash").detach();
		$("div.videoContainer").hide();
		$("#altmisinciyil").empty();
		return false;
	});
	

	
	/**/
	
});


function $get(key, url) {
    if (arguments.length < 2) url = location.href;
    if (arguments.length > 0 && key != "") {
        if (key == "#") {
            var regex = new RegExp("[#]([^$]*)");
        } else if (key == "?") {
            var regex = new RegExp("[?]([^#$]*)");
        } else {
            var regex = new RegExp("[?&]" + key + "=([^&#]*)");
        }
        var results = regex.exec(url);
        return (results == null) ? "" : results[1];
    } else {
        url = url.split("?");
        var results = {};
        if (url.length > 1) {
            url = url[1].split("#");
            if (url.length > 1) results["hash"] = url[1];
            url[0].split("&").each(function (item, index) {
                item = item.split("=");
                results[item[0]] = item[1];
            });
        }
        return results;
    }
};

function getmailid() {
    if ($get("kayitNo") != "" && $get("dogrulamaKodu") != "") {
        kno = $get("kayitNo");
        dcode = $get("dogrulamaKodu");
        ad = $get("ad");
        soyad = $get("soyad");
        email = $get("email");
        framesrc = "http://www.fercomotor.com.tr/kayit/adresdogrula.asp?kayitNo=" + kno + "&dogrulamaKodu=" + dcode  +"&ad="+ ad +"&soyad="+ soyad +"&email="+ email;
   
        
        $("#kayitframe").attr("src", framesrc);
        alert(framesrc)
    }
};
