
var w = window;
w.speed = 250;
w.pages = Array('omne', 'prace', 'kontakt');
w.works = Array('MyOwPaStranka', 'MyOwPaSystem', 'StaraVoda', 'HairExpress');
w.current = 0;
function find(needle, haystack)
{
toReturn = "X";
$.each(haystack, function(i, val){
if(needle == val)
{
toReturn = i;
found = true;
}
});
return toReturn;
};
$.fn.hoverIn = function(speed)
{
if( speed == undefined ){speed = w.speed/1.7;}
$("img", this).stop().fadeTo(speed, 0);
$("p", this).stop().animate({color: "#00142e"}, speed);
$("span", this).stop().animate({color: "#0c5ed0"}, speed);
};
$.fn.hoverOut = function(speed)
{
if( speed == undefined ){speed = w.speed/1.7;}
$("img", this).stop().fadeTo(speed, 1);
$("p", this).stop().animate({color: "#4e6374"}, speed);
$("span", this).stop().animate({color: "#666666"}, speed);
};
$.fn.goTo = function(where)
{
var effects = new Array();
if(!$.browser.msie)
{
effects['hide_up'] = { marginTop: '-40px', opacity: 0 };
effects['hide_down'] = { marginTop: '40px', opacity: 0 };
effects['show_up'] = { marginTop: 0, opacity: 1 };
effects['show_down'] = { marginTop: 0, opacity: 1 };
}
else
{
effects['hide_up'] = { marginTop: '-40px' };
effects['hide_down'] = { marginTop: '40px' };
effects['show_up'] = { marginTop: 0 };
effects['show_down'] = { marginTop: 0 };
}
if(where == undefined)
{ where = $(this).attr('id'); }
whereI = find(where, w.pages);
if(w.current < whereI)
{
$(".shown")
.animate( effects['hide_up'], w.speed, function(){
$(".shown")
.css('marginTop', 0)
.removeClass('shown')
.addClass('hidden');
$("." + where)
.removeClass('hidden')
.addClass('shown')
.css('marginTop', '40px')
.animate( effects['show_up'], w.speed);
w.current = whereI;
});
};
if(w.current > whereI)
{
$(".shown")
.animate( effects['hide_down'], w.speed, function(){
$(".shown")
.css('marginTop', 0)
.removeClass('shown')
.addClass('hidden');
$("." + where)
.removeClass('hidden')
.addClass('shown')
.css('marginTop', '-40px')
.animate( effects['show_down'], w.speed);
w.current = whereI;
});
};
};
function changeWork(work)
{


$("#title").removeAttr('src');
$("#title").attr('src', 'img/prace/' + work + '-title.png');
$("#img img").detach();$("#img").html("<img>");
$("#img img").attr('src', 'img/prace/' + work + '.jpg');
$("#popis").load('prace/' + work + '.html');
currWorkI = find(work, w.works);
if(currWorkI == w.works.length - 1)currWorkI = -1;
$("#next").attr('href', "#"+w.works[currWorkI+1]);
currWorkI = find(work, w.works);
if(currWorkI == 0)currWorkI = w.works.length;
$("#prev").attr('href', "#"+w.works[currWorkI-1]);
};
function fastChange(where)
{
$(".shown")
.removeClass('shown')
.addClass('hidden');
$("." + where)
.removeClass('hidden')
.addClass('shown');
}
function intro()
{
var i1 = setTimeout('$(".intro1, #intro1").hoverIn(500);', 0);
var i1 = setTimeout('$(".intro1, #intro1").hoverOut(500);', 1000);
var i2 = setTimeout('$(".intro2, #intro2").hoverIn(500);', 2000);
var i2 = setTimeout('$(".intro2, #intro2").hoverOut(500);', 3000);
var i3 = setTimeout('$(".intro3, #intro3").hoverIn(500);', 4000);
var i3 = setTimeout('$(".intro3, #intro3").hoverOut(500);', 5000);
var i4 = setTimeout('$(".intro4, #intro4").hoverIn(500);', 6000);
var i4 = setTimeout('$(".intro4, #intro4").hoverOut(500);', 7000);
};

$(document).ready(function(){


query = document.location.href.split("#")[1];
if (query != "omne")
{
intro();
}
if (query == "omne"||
query == "prace" ||
query == "kontakt" ) 
{
fastChange(query);
}
if (find(query, w.works) != "X")
{
changeWork(query);
$("#list").hide();
$("#one").show();
fastChange("prace");
}
else
{
$("#one").hide();
}

$(".hoverEffect").hover(function(){
$(this).hoverIn();
}, function(){
$(this).hoverOut();
});
$("#logo").click(function(){
$(this).goTo('omne');
intro();
});
$("#menu a").click(function(){
$(this).goTo();
if($(this).is("#prace"))
{ $("#list").fadeIn(w.speed, function(){ $("#one").fadeOut(w.speed); }); }
});
$("#blocks a").hover(function(){
for(i = 1;i<=4;i++)
{
if($(this).hasClass('intro' + i))
{ $("#intro" + i).hoverIn(); }
}
$(this).hoverIn();
},function(){
for(i = 1;i<=4;i++)
{
if($(this).hasClass('intro' + i))
{ $("#intro" + i).hoverOut(); }
}
$(this).hoverOut();
});
$("#intro a").hover(function(){
$("." + $(this).attr('id')).hoverIn();
$(this).hoverIn();
},function(){
$("." + $(this).attr('id')).hoverOut();
$(this).hoverOut();
});


$(".praca").click(function(){

changeWork($(this).attr('id'));
$("#list").fadeOut(w.speed, function(){ $("#one").fadeIn(w.speed); });
});
var effects;
w.effects = new Array();
if(!$.browser.msie)
{
w.effects['goLeft'] = {marginLeft: '10px', opacity: 0};
w.effects['goRight'] = {marginLeft: '50px', opacity: 0};
w.effects['goCenter'] = {marginLeft: '30px', opacity: 1};
}
else
{
w.effects['goLeft'] = {};
w.effects['goRight'] = {};
w.effects['goCenter'] = {};
}
$("#prev").click(function(){
$("#praca").animate(w.effects['goRight'], window.speed*2, function(){

goTo = find(w.currentWork, window.works)-1;
if(goTo >= 0){ loadWork = w.works[goTo]; }
else{ loadWork = w.works[w.works.length-1]; }
w.currentWork = loadWork;

changeWork(loadWork);
if(!$.browser.msie)$("#praca").css('marginLeft', '10px');
$("#praca").animate(w.effects['goCenter'], window.speed*3);
});
});
$("#next").click(function(){
$("#praca").animate(w.effects['goLeft'], window.speed*2, function(){

goTo = find(w.currentWork, window.works)+1;
if(goTo < w.works.length){ loadWork = w.works[goTo]; }
else{ loadWork = w.works[0]; }
w.currentWork = loadWork;

changeWork(loadWork);
if(!$.browser.msie)$("#praca").css('marginLeft', '50px');
$("#praca").animate(w.effects['goCenter'], window.speed*3);
});
});


$(".odoslat").click(function(){
conti = true; 

if($.trim($("input[name|=meno]").val()) == '')
{ $("#menoCapt").css('color', '#0670DB'); $("input[name|=meno]").next().css('color', '#0670DB'); conti = false; }
else
{ $("#menoCapt").css('color', '#00132C'); $("input[name|=meno]").next().css('color', '#4E6374'); }

var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
if(!pattern.test($.trim($("input[name|=email]").val())))
{ $("#emailCapt").css('color', '#0670DB'); $("input[name|=email]").next().css('color', '#0670DB'); conti = false; }
else
{ $("#emailCapt").css('color', '#00132C'); $("input[name|=email]").next().css('color', '#4E6374'); }

if($.trim($("textarea[name|=sprava]").val()) == '')
{ $("#spravaCapt").css('color', '#0670DB'); conti = false; }
else
{ $("#spravaCapt").css('color', '#00132C'); }

if(conti)
{
$("#content").fadeTo(window.speed, 0.5);
$("#loading").show();
$.post('mail.php', {
meno: $("input[name|=meno]").val(),
email: $("input[name|=email]").val(),
im: $("input[name|=im]").val(),
sprava: $("textarea[name|=sprava]").val()
}, function(){
$("#content").fadeTo(window.speed, 1);
$("#loading").hide();
$("#odoslane").show().fadeTo(window.speed, 1);
x = setTimeout("$('#odoslane').fadeOut(300, function(){$('input, textarea').val('')});", 1500);
});
};
});
});
