time = 3; // Seconds between each slide
time *= 1000; // Multiply by 1000 to get ms.

run = true; // Tell the app to run the animations
current_slide = 2; // The default slide
/*$(".bigservice").hover(function(){
	run = 0;
    $(this).addClass("hover");
}
,
function(){
    $(this).removeClass("hover");
}
);*/
$(".servicecover, .hidden").hover(function(){
	run = 0;
    $(this).parent().addClass("hover");
    //$("#firstpagemenu li, #submenu li").removeClass("fakehover");
	//if(!$.browser.msie || !$.browser.version=="6.0")
	//	$("#firstpagemenu li, #submenu li").removeClass("hover");
	hover($(this).parent().index());
},
function(){
    $(this).parent().removeClass("hover");
});
$(".homecover").hover(function(){
    $(this).parent().parent().parent().addClass("homehover");
},
function(){
    $(this).parent().parent().parent().removeClass("homehover");
});
$(".boostcover").hover(function(){
    $(this).parent().parent().parent().addClass("boosthover");
},
function(){
    $(this).parent().parent().parent().removeClass("boosthover");
});
$(".summercover").hover(function(){
    $(this).parent().parent().parent().addClass("summerhover");
},
function(){
    $(this).parent().parent().parent().removeClass("summerhover");
});

$("input.send").hover(function(){
    $(this).attr("src",$(this).attr('hvr'));
},
function(){
    $(this).attr("src",$(this).attr('nrm'));
});


//#$(".slide").fadeIn();
//$(".slide:first").fadeOut();
//$(".slide:last").fadeIn();

function hover(current_slide){
		$(".slide").each(function(){
			if($(this).index()==current_slide){
				//$(this).show();
				$(this).fadeTo("slow", 1);
				}
			else{
				$(this).clearQueue();
				$(this).fadeTo("slow", 0);
				$(this).hide();
			}
		});
		$("li.bigservice").each(function(){
			
			if($(this).index()==current_slide)
				$(this).addClass("fakehover");
			else
				$(this).removeClass("fakehover");
		});
		$("li.biginline").each(function(){
				$(this).removeClass("fakehover");
		});
}
first = true;
function show(){
	if(run && !first && current_slide == 2){
		//run = false;
	}
	if(run){
		hover(current_slide);
		current_slide++;
		if(current_slide>=3)
			current_slide = 0;
		first = false;
		setTimeout("show()", time);	
	}
}

function resizeWindow(){
	$(window).scrollTop(0);
	if($(window).height()<770){
		$("#page.first").css("height","770px");
		$("body.first").css("height","770px");
		$("body.first").css("overflow","auto");
	}else{
		$("#page.first").css("height",$(window).height() + "px");
		$("body.first").css("height",$(window).height() + "px");
		/*$("#page.first").css("height","900px");
		$("body.first").css("height","900px");*/
		$("body.first").css("overflow","hidden");
		$("#page.first").css("overflow","hidden");
	}
}
$('.callme input.number').val("Fyll i ditt nummer");
$('.callme input.number').focus(function(){
	if($(this).val() == "Fyll i ditt nummer")
		$(this).val("");
	else if($(this).val() == "")
		$(this).val("Fyll i ditt nummer");
	
});
$('.callme input.number').blur(function(){
	if($(this).val() == "Fyll i ditt nummer")
		$(this).val("");
	else if($(this).val() == "")
		$(this).val("Fyll i ditt nummer");
	
});
$(".callme .img img").hover(function(){
	var ovr = $(this).attr("ovr");
	$(this).attr("ovr", $(this).attr("src"));
	$(this).attr("src", ovr);
});
$(".callme .img img").click(function(){
	var pos = $(this).position();
	var w = "393";
	var h = "170";
	var c = "http://myacademy.se/callme.php";
	openPop(parseInt(pos.top) - parseInt(h) + 4 , pos.left, w, h, c, 1);
});
$("#price").click(function(){
	var pos = $(this).position();
	var w = "410";
	var h = "427";
	var c = "http://myacademy.se/price.php?p=" + $(this).attr("val");
	openPop(100, 200, w, h, c, 1);
	overlay();
	return false;
});
if(popupcall){
	var pos = $(".callme .img img").position();
	var w = "393";
	var h = "170";
	var c = "http://myacademy.se/callme.php?ort="+ort+"&number="+number+"&sent="+call;
	openPop(parseInt(pos.top) - parseInt(h) + 4 , pos.left, w, h, c, 1);
}
function openPop(t,left,w,h,c,ajax){
	if(ajax){
		l = c;
		c = "Laddar ...";
	}	
	if($("#pop").attr("id")!="pop"){
	//	$("body").append("<div id='overlay' onclick='closePop()' style='position:fixed; top:0; left:0; right:0; bottom:0; background:#000; opacity:0.5; z-index:999'></div>");
		$("body").append("<div id='pop' style=' position:absolute; z-index:1000; visibility:hidden;'>"+c+"</div>");
	}
		$("#pop").css("top", t);
		$("#pop").css("left",left);
		$("#pop").css("width", w + "px");
		$("#pop").css("height", h + "px");
//		$("#pop").css("top", parseInt($("#pop").css("top")) - parseInt($("#pop").css("height")) + 4 + "px");
		if(ajax){
		    $("#pop").html("");
			$.get(l, function(data) {
				$("#pop").html(data);
				$("#pop").css("visibility","visible");
			});
		}else	
				$("#pop").css("visibility","visible");
	
}
function overlay(){
	$("body").append("<div id='overlay' onclick='closePop()' style='display:none; position:fixed; top:0; left:0; right:0; bottom:0; background:#000; z-index:999'></div>");
	$("#overlay").fadeTo("slow", 0.5);
	
}
function closePop(){
	$("#pop").remove();
	$("#overlay").remove();
}
$(".quote p").hide();
$(".quote").each(function(){
	var boxIndex = $(this).index(".quote");
	if($(".quote:eq("+boxIndex+") p").length>0){
		$(".quote:eq("+boxIndex+")").append("<div class='nav'>Citat: </div>");
		$(".quote:eq("+boxIndex+") p").each(function(){
			var Cclass = "";
			if($(this).index()==0){
				$(this).fadeIn();
				Cclass = "current";
			}
			$(".quote:eq("+boxIndex+") .nav").append("<a href='#citat"+$(this).index()+"' class='citat"+$(this).index()+" "+Cclass+"'>"+(parseInt($(this).index())+1)+"</a> | ");
		});
	}
});
var slideQuotes = true;
var quote_timeout = 5000;
function Quote(qi, boxIndex){
	if(!slideQuotes)
		return;
	$(".quote:eq("+boxIndex+") .nav a").removeClass("current");
	$(".quote:eq("+boxIndex+") .nav a:eq("+qi+")").addClass("current");
	$(".quote:eq("+boxIndex+") p").hide();
	$(".quote:eq("+boxIndex+") p:eq("+qi+")").fadeIn();
	var next = qi + 1;
	//console.log(next, $(".quote:eq("+boxIndex+") .nav a").length);
	if(next==$(".quote:eq("+boxIndex+") .nav a").length){
		next = 0;
	}
	if(slideQuotes)
    	setTimeout("Quote("+next+", "+boxIndex+")", quote_timeout);
}
setTimeout("Quote(1, 0)", quote_timeout);
setTimeout("Quote(1, 1)", quote_timeout);
$(".quote .nav a").click(function(){
	slideQuotes = false;
	var boxIndex = $(this).parent().parent().index(".quote");
	var index = $(this).index();
	$(".quote:eq("+boxIndex+") .nav a").removeClass("current");
	$(this).addClass("current");
	$(".quote:eq("+boxIndex+") p").hide();
	$(".quote:eq("+boxIndex+") p:eq("+index+")").fadeIn();
});

$("#pop a[title^=]").click(function(){alert("test");});
$("table tr:even td").addClass("odd"); 
