$(function()
	{
	$('#gearlistScrollPane').jScrollPane({scrollbarWidth: 15, containedHeight: 910});
	$('#newsletterScrollPane').jScrollPane({scrollbarWidth: 15, containedHeight: 2050});
	$('#fyiScrollPane').jScrollPane({scrollbarWidth: 15, containedHeight: 540});
	});


$("ul.engThumb li").hover(function() {

	$(this).css({'z-index' : '100'});
	$(this).find('div.engContainer').stop()
		.animate({
			marginTop: '-10px', 
			marginLeft: '-10px', 
			top: '0', 
			left: '0', 
			width: '158px', 
			height: '140px',
			padding: '12px'
		}, 200);	
	
	$(this).find('div.engText').append("<h3>"+ $(this).find('img').attr('alt') +"</h3>");
	
	} , function() {
	
	$(this).find('div.engText').empty();
	$(this).css({'z-index' : '0'});
	$(this).find('div.engContainer').stop()
		.animate({
			marginTop: '0', 
			marginLeft: '0',
			top: '0', 
			left: '0', 
			width: '158px', 
			height: '128px', 
			padding: '0px'
		}, 400);
});


$(document).ready(function(){
 
	$(".btn-slide").click(function(){
		$("#subscribePanel").slideToggle("slow");
		$(this).toggleClass("active"); return false;
	});
	
	 
});


$("#newsLetterSubscription").click(function(){ 
jQuery.facebox(function() { 

			var subscription="<div id='subscribe'><div id='subscriptionHeader'>Please fill in your details to subscribe to our monthly newsletter.</div>"+
							"<div id='subscribeForm'><div id='subscribeForma'>"+
							"<fieldset id='subscrForm'>"+
								"<label for='sName' class='error' id='sNameError'>Your name.</label>"+
								"<label for='sEmail' class='error' id='sEmailError'>An email is required.</label>"+
								"<label  for='sEmail' class='error' id='sEmailWrong'>Your email is wrong.</label>"+
								"<table>"+
									"<tr><td>"+
										"<input type='text' name='sName' class='inp' id='sName' value='' />"+
									"</td><td>"+
										"<div class='sLabelCell'>"+
										"<label for='sName'>name</label></div>"+
									"</td><td/></tr>"+
									"<tr><td>"+
										"<input type='text' name='sEmail'  class='inp' id='sEmail' value='' />"+
									"</td><td>"+
										"<div class='sLabelCell'>"+
											"<label for='sEmail'>email</label></div></td><td class='subscribeButton'><input type='submit' name='submit' class='sButton' value='' id='sSend'/>"+
									"</td></tr>"+
								"</table>";
							"</fieldset>"+
							"</div></div></div>";
            jQuery.facebox(subscription);
			});
});
			
var leftslideropen=true;
var rightslideropen=true;

$("#leftpanelbuttoncontainer").click(function(){ 

	if (!leftslideropen)
	{
	$("#leftslider").animate( { left:"-130px"}, 300 );	
	document.getElementById("leftpanelbuttoncontainer").innerHTML="<div id='leftslidebuttonright'></div>";
	leftslideropen=true;
	}
	else
	{
	$("#leftslider").animate( { left:"-34px"}, 200 ); 
	document.getElementById("leftpanelbuttoncontainer").innerHTML="<div id='leftslidebuttonleft'></div>";
	leftslideropen=false;
	}
});


$("#rightslider").click(function(){
	
	if (!rightslideropen)
		{
		$("#rightslider").animate( {left: "801px"}, 300 ); 
		document.getElementById("rightpanelbuttoncontainer").innerHTML="<div id='rightslidebuttonleft'></div>";
		rightslideropen=true;
		}
	else
		{
		$("#rightslider").animate( { left:"705px"}, 200 );
		document.getElementById("rightpanelbuttoncontainer").innerHTML="<div id='rightslidebuttonright'></div>";
		rightslideropen=false;
		}
});


var imagesWithToolTip= new Array ("/studioGallery/control/large/14.jpg");
var imagesTooltips = new Array ("<h1>Apple Mac Pro</h1><br/><ul><li>Two 2.26GHz Quad-Core Intel Xeon</li><li>Apogee Symphony 64 PCIe Card</li><li>Steinberg NUENDO 4-Logic Pro 8</li></ul>");

(function($){ $.fn.simpletooltip = function(){
	return this.each(function() {
		var img= $(this).attr("src");
		var hasTooltip=false;
		
		for (key in imagesWithToolTip)
		{
		if (img.indexOf(imagesWithToolTip[key]) >= 0)
			{
			text= imagesTooltips[key];
			hasTooltip=true;
			break;
			}		
		}
		if (!hasTooltip) 
		{
		$("#simpleTooltip").remove();
		return;
		}
		
		$(this).attr("title", "");
		if(text != undefined) {	
		
		$("#simpleTooltip").remove();
		$(this).attr("title", text); 
		$("body").append("<div id='simpleTooltip'>" + text + "</div>");
		$("#simpleTooltip").css("left", "55%").css("top", "12%").fadeIn("medium");
	
			$(this).hover(function(e){
				$(this).attr("title", ""); 
				$("body").append("<div id='simpleTooltip'>" + text + "</div>");
				$("#simpleTooltip").css("left", "55%").css("top", "12%").fadeIn("medium");
			}, 
						
			function(){
				$("#simpleTooltip").remove();
				$(this).attr("title", text);  			
			});					
		}			
	});

}
})(jQuery);

    // wrap as a jQuery plugin and pass jQuery in to our anoymous function
    (function ($) {
        $.fn.cross = function (options) {
            return this.each(function (i) { 
                // cache the copy of jQuery(this) - the start image
                var $$ = $(this);
                
                // get the target from the backgroundImage + regexp
                var target = $$.css('backgroundImage').replace(/^url|[\(\)'"]/g, '');
 
                // nice long chain: wrap img element in span
                $$.wrap('<span style="position: absolute; top:0px; left:0px;"></span>')
                    // change selector to parent - i.e. newly created span
                    .parent()
                    // prepend a new image inside the span
                    .prepend('<img>')
                    // change the selector to the newly created image
                    .find(':first-child')
                    // set the image to the target
                    .attr('src', target);
 
                // the CSS styling of the start image needs to be handled
                // differently for different browsers
                if ($.browser.msie || $.browser.mozilla) {
                    $$.css({
                        'position' : 'absolute', 
                        'left' : 0,
                        'background' : '',
                        'top' : 0
                    });
                } else if ($.browser.opera && $.browser.version < 9.5) {
                    // Browser sniffing is bad - however opera < 9.5 has a render bug 
                    // so this is required to get around it we can't apply the 'top' : 0 
                    // separately because Mozilla strips the style set originally somehow...                    
                    $$.css({
                        'position' : 'absolute', 
                        'left' : 0,
                        'background' : '',
                        'top' : "0"
                    });
                } else { // Safari
                    $$.css({
                        'position' : 'absolute', 
                        'left' : 0,
                        'background' : ''
                    });
                }
 
                // similar effect as single image technique, except using .animate 
                // which will handle the fading up from the right opacity for us
                $$.hover(function () {
                    $$.stop().animate({
                        opacity: 0
                    }, 600);
                }, function () {
                    $$.stop().animate({
                        opacity: 1
                    }, 600);
                });
            });
        };
        
    })(jQuery);
    
    // note that this uses the .bind('load') on the window object, rather than $(document).ready() 
    // because .ready() fires before the images have loaded, but we need to fire *after* because
    // our code relies on the dimensions of the images already in place.
    $(window).bind('load', function () {
        $('img.fadeImg').cross();
    });

	
$(function () {
        // find the div.fade elements and hook the hover event
        $('.fadeImage').hover(function() {
		$(this).stop().animate({ 
        src: "url(images/mapRooms/loungeRoom2.jpg)"

		}, 1500 );
		
		
        }, function () {
            
        });
    });	
	
	

var siteNavigation = {
    mainNav: function() {
        $('a.carouselBtn, a.sideCarouselBtn').css({backgroundPosition: "0 -27px"});
        $('a.carouselBtn, a.sideCarouselBtn').mouseover(function(){
            $(this).stop().animate({backgroundPosition:"(0px 0px)"}, {duration:300})
        })
        .mouseout(function(){
            $(this).stop().animate({backgroundPosition:"(0 -27px)"}, {duration:300, complete:function(){
                $(this).css({backgroundPosition: "0px -27px"})
            }})
        })
    }, 
	redirectUrl: function(){
		var hash = window.location.hash.substr(1);
        var whereToSc = 0;
        $('.home').removeClass("activeButton");
        if(hash != ""){
            if($('a[rel="' + hash + '"]').length > 0){
               $('a[rel="' + hash + '"]').parent().addClass('activeButton');
               whereToSc = parseInt($('a[rel="' + hash + '"]').attr('id').split('_')[1]);
               $('a[rel="' + hash + '"]').parent().addClass('activeButton');
            }
            else {
                $('a[rel="home"]').parent().addClass('activeButton');
            }
        }
        else {
            if (location.pathname == "")
                $('a[rel="home"]').parent().addClass('activeButton');
            else {
                var pathName = location.pathname.match(/.*\/(.*)\.html$/);       //note ro regular exp na ginei /^(.*)\.html$/   anti gia   /.*\/(.*)\.html$/
                pathName = RegExp.$1;
                if(pathName == 'construction')
                    pathName = 'constr';
                if(pathName == 'mastering')
                    pathName = 'master';
                if(pathName == 'recordDeal')
                    pathName = 'record';

                if(pathName == "")
                   pathName = 'home';
                whereToSc = parseInt($('a[rel="' + pathName + '"]').attr('id').split('_')[1]);
                $('a[rel="' + pathName + '"]').parent().addClass('activeButton');
            }
                
        }
        //alert((-(parseInt(whereToSc) * 730 )) +" apo redirect");
        $('ul.jcarousel-list').stop().animate({
            'left': -(parseInt(whereToSc) * 730)
        });
        if (window.location.hash == '#bookings'){
            smallMaps.initialFade();
        }
	},
    customCarousel: function(){
        $('.carouselBtn, .tipBtn, .insideLink').click(function() {
             var thisRel = $(this).attr('rel');
            var thisID; 
            if(window.location.hash != '#'+thisRel){ 
                if(parseInt($(this).attr('id')) != 'NaN'){	
					try {thisID = $('#navigation a[rel="' + thisRel + '"]').attr('id').split('_')[1];}
					catch(err) {
								try {thisID = $('#leftpanelcontainer a[rel="' + thisRel + '"]').attr('id').split('_')[1];}
								catch (err) {thisID = $('#rightpanelcontainer a[rel="' + thisRel + '"]').attr('id').split('_')[1];}
								}
				}
                else{
                    thisID = $(this).attr('id').split('_')[1];
                }
                $('#navigation a').each(function() { 
                    if($(this).parent().hasClass('activeButton')){
                        $(this).parent().removeClass('activeButton');
                    }
                });
				
				$('#leftpanelcontainer a').each(function() { 
                    if($(this).parent().hasClass('activeButton')){
                        $(this).parent().removeClass('activeButton');
                    }
                });

				$('#rightpanelcontainer a').each(function() { 
                    if($(this).parent().hasClass('activeButton')){
                        $(this).parent().removeClass('activeButton');
                    }
                });
				
                var posTo = parseInt(thisID) * 730; 
				$('#navigation a[rel="' + thisRel + '"]').parent().addClass('activeButton'); 
				$('#leftpanelcontainer a[rel="' + thisRel + '"]').parent().addClass('activeButton');
				$('#rightpanelcontainer a[rel="' + thisRel + '"]').parent().addClass('activeButton');
				$('ul.jcarousel-list').stop().animate({
                    'left': -posTo
                });
                window.location.hash = thisRel;
            
			}
            else if(window.location.hash != 'contact' && $(this).attr('id') == 'contactEnv'){
                var mailWIn = window.open('mailto:info@fabricaudio.com');
                if(jQuery.support.opacity)
                    mailWIn.close();
            }
            return false;
        });
		
		$('.sideCarouselBtn').click(function() {
			if(window.location.hash != '#'+thisRel) {
			var thisRel = $(this).attr('rel');
			
			//disabling right panel buttons
			if (thisRel == "music" || thisRel == "faq" || thisRel == "backl")
				return false;
			
            var thisID = $(this).attr('id').split('_')[1];
			var posTo = parseInt(thisID) * 730;
				
		   $('#leftpanelcontainer a').each(function() { 
                    if($(this).parent().hasClass('activeButton')){
                        $(this).parent().removeClass('activeButton');
                    }
            });
			
			$('#rightpanelcontainer a').each(function() { 
                    if($(this).parent().hasClass('activeButton')){
                        $(this).parent().removeClass('activeButton');
                    }
            });
			
			$('#navigation a').each(function() { 
                  if($(this).parent().hasClass('activeButton')){
                        $(this).parent().removeClass('activeButton');
                   }
            });
			$('#leftpanelcontainer a[rel="' + thisRel + '"]').parent().addClass('activeButton');
			$('#rightpanelcontainer a[rel="' + thisRel + '"]').parent().addClass('activeButton');
			$('ul.jcarousel-list').stop().animate({
                    'left': -posTo
            });
            

			
			window.location.hash = thisRel; 
			return false;}
		});
		
		
		
        
    },
    initConent: function(){ 
        $('#navigation a').each(function(i) {
            var urlToLoad = jQuery(this).attr('href').replace('.html','');
            var urlTemp = "js=on&page=" + urlToLoad;
            if(i != 0){
                $.get("fabricaudiosite.php", urlTemp, function(fata){
                    var hook = '<li class="jcarousel-item" id="content_' + (i+1) + '">'+ fata + '</li>';
                    $('.jcarousel-list').append(hook);
                });
            }
        });
    }, 
	fading: function() {
		$('.service').livequery(function() {
            var ratesFading;
			if($(this).is("#serviceLast")){
				//$(this).animate({"opacity": 1}, 1500 );
				//$(this).children(".smallMap").css({"background-position" : "0 -88px"});
			}
			else {
				//$(this).animate({"opacity": 0.4}, 'slow');
			}
			$(this).hover(
				function () {
					if($(this).css('opacity') !== '1'){
						ratesFading = $(this);
						//$(this).siblings(".service").animate({"opacity": 0.5}, 'normal');
						//$(this).siblings(".service").children(".smallMap").css({"background-position" : "0 0"});
						//$(this).children(".smallMap").css({"background-position" : "0 -88px"});
						ratesFading.stop().animate({"opacity": 1}, 'normal');
					}
				}, 
				function () {
				}
			);
		});
	},
	init: function() {
		//this.subContent();
		//this.fading();
        $('.jcarousel-item').show();
        $('.activeButton').removeClass('activeButton');
        this.mainNav();
       // this.initConent();
        this.customCarousel();
		this.redirectUrl();
	}
};
var smallMaps = {
    initialFade: function(){
        var myTimeout = setTimeout(function(){
            $('.smallMapFade').stop().animate({
                opacity: 0
            }, 1000);
                clearTimeout(myTimeout);
        }, 1500);
    },
    smallMapFade: function(){
        $('.service').livequery(function(){
            $(this).hover(
                function () {
                    $(this).children('.smallMapFade').stop().animate({
                        opacity: 1
                    }, 250);
                    $(this).siblings().children('.smallMapFade').stop().animate({
                        opacity: 0
                    }, 2000);
                },
                function () {
                
            });
        });
    }
};
var toolTipPlease = {
	makeToolTips: function(whichToolTip, toolTipTrigger, topPositie, leftPositie, hideDelay, direction, checkActive) {
		$(toolTipTrigger).livequery(function(){
            var distance = 10;
            var bdistance = 30;
            var time = 250;
            var btime = 750;
            var hideDelayTimer = null;

            var beingShown = false;
            var shown = false;
            //var direx = $(direction);
            var trigger = $(toolTipTrigger);
            var info = $(whichToolTip).css('opacity', 0);
            $(trigger).click(function() {
                return false;
            });
            if(checkActive != undefined) {
                $(whichToolTip + ' a').click(function(){
                    info.animate({
                            right: '-=' + bdistance + 'px',
                            opacity: 0
                        }, btime, 'swing', function () {
                            shown = false;
                            info.css('display', 'none');
                    });
                });
            }
            $([trigger.get(0), info.get(0)]).mouseover(function () { 
                if(checkActive == undefined || window.location.hash == checkActive){
                    if (hideDelayTimer) clearTimeout(hideDelayTimer);
                    if (beingShown || shown) {
                        // don't trigger the animation again
                        return;
                    } else {
                        // reset position of info box
                        beingShown = true;
                        if (direction != 2){
                            info.css({
                                top: topPositie,
                                left: leftPositie,
                                display: 'block'
                            }).animate({
                                top: '-=' + distance + 'px',
                                opacity: 1
                            }, time, 'swing', function() {
                                beingShown = false;
                                shown = true;
                            });
                        }
                        else{
                            info.css({
                                bottom: topPositie,
                                right: leftPositie,
                                display: 'block'
                            });
                            info.stop().animate({
                                right: '-=' + bdistance + 'px',
                                opacity: 1
                            }, btime, 'swing', function() {
                                beingShown = false;
                                shown = true;
                            });
                        }
                    }
                }
            }).mouseout(function () {
                    if(checkActive == undefined || window.location.hash == checkActive){
                    if (hideDelayTimer) clearTimeout(hideDelayTimer);
                    hideDelayTimer = setTimeout(function () {
                        hideDelayTimer = null;
                        if (direction != 2){
                            info.animate({
                                top: '-=' + distance + 'px',
                                opacity: 0
                            }, time, 'swing', function () {
                                shown = false;
                                info.css('display', 'none');
                            });
                        }
                        else{
                            info.animate({
                                right: '-=' + bdistance + 'px',
                                opacity: 0
                            }, btime, 'swing', function () {
                                shown = false;
                                info.css('display', 'none');
                            });
                        }
                        }, hideDelay);
                }
                return false;
            });
        });
	}
};
var constGallery = {
    fancy: function(){
        $('#galImages a').fancybox({
            'overlayShow':	true,
            'zoomSpeedIn': 300,
            'zoomSpeedOut': 300
        });
    }, 
    nav: function(){ 
        var galleyNum  = 1;
        var gallSize   = 7;
        var imgNum     = 171;
        var thumbTemp  = '<a class="thumb" href="images/large/fabric%num%.jpg" title="%title%" rel="construction%relNum%"><img class="fade" alt="" src="images/thumbsBW/fabric%num%.jpg"/><span class="fadeLayer"></span></a>';
        var titleTexts = [];
        $.get('images/thumbsBW/gallerytitles.html', '', function(data){
            titleTexts = data.split(/\n/);
        });
        $('.galleryBtn, .item').livequery(function(){
            $(this).click(function(){
                if($(this).attr('id') == 'galleryNext' && galleyNum < gallSize){
                    galleyNum++;
                    $(this).parent().siblings('galleryMeter').children().removeClass('activeItem');
                    makeAjax(galleyNum);
                }
                else if($(this).attr('id') == 'galleryBack' && galleyNum > 1) {
                    galleyNum--;
                    makeAjax(galleyNum);
                }
                else if($(this).attr('class') == 'item') {
                    galleyNum = parseInt($(this).children('a').attr('href'));
                    $(this).siblings().removeClass('activeItem');
                    $(this).addClass('activeItem');
                    makeAjax(galleyNum);
                }
                else
                    return false;

                $('.item').each(function(){
                    if($(this).text() == galleyNum)
                        $(this).addClass('activeItem');
                    else
                        $(this).removeClass('activeItem');
                });
                
                return false;
            });
        });
        function makeAjax(n){
            var hookm = [];
            hookm[0] = '<div id="hookImages">';
            for(var i = 0; i < 22; i++){
                var u = n * 22 + i;
                if (u<imgNum)
                    hookm.push(thumbTemp.replace(/%num%/g, u + 1).replace(/%title%/g, titleTexts[u]).replace(/%relNum%/, galleyNum));
                else
                    break;
            }
            hookm.push('</div>');
            $('#galImages').stop(true).fadeOut(function(){
                var select = $(this).siblings('#galleryPage').children('b');
                var page = select.text().replace(/\d/g,galleyNum);
                select.html(page);
                $(this).empty();
            });
            $('#galImages').queue(function(){
                $('#loader').show('fast', function(){
                    $('#galImages').html(hookm.join(''));
                    $('#loader').hide(function(){
                        $('#galImages').fadeIn();
                        constGallery.fancy();
                    });
                });
            });
        }
    },
    crossFade: function(){
        $('.thumb').livequery(function(){
            $(this).hover(
                function(){
                    if(!thisBrowser.isIE && !thisBrowser.isChrome )
                        $(this).children().eq(1).stop().animate({'opacity': 0},250);
                    else
                        $(this).children().eq(1).hide();
                },
                function(){
                    if(!thisBrowser.isIE && !thisBrowser.isChrome )
                        $(this).children().eq(1).stop().animate({'opacity': 1},500);
                    else
                        $(this).children().eq(1).show();
                }
            )
        });
    },
    init: function(){
        this.nav();
        this.crossFade();
    }
};
var webStart = {
	initializePage: function () {
		$('#cpr').click(function() {
			if($(this).children('#cprContent').is(':hidden')) {
				$(this).children('#cprContent').show();
				$(this).animate({ right: "-115px" }, 'slow');
			}
			else {
				$(this).animate({ right: "-15px" }, 'slow', function (){
					$(this).children('#cprContent').hide();													 
				});	
			}
		});
		$(window).load(function () {
			//$("#siteLoading,#siteLoadOverlay_Frame").fadeOut("fast").remove();
			$("#siteLoading").fadeOut('normal', function (){
				$(this).remove();											
			});
		});
        $('.jcarousel-list').css('width', 7300 ); //730px
        $("a.externalLink").livequery(function(){
            $(this).attr("target","_blank");
        });
		
		
		//if (window.location.hash == "#partners" || window.location.hash == "#gear" || window.location.hash == "#eng") 
		{
		$("#leftslider").animate( { left:"-130px"}, 300 );	
		document.getElementById("leftpanelbuttoncontainer").innerHTML="<div id='leftslidebuttonright'></div>";
		leftslideropen=true;
		}
		//else if (window.location.hash == "#news" || window.location.hash == "#fyi") 
		{
		$("#rightslider").animate( {left: "801px"}, 300 ); 
		document.getElementById("rightpanelbuttoncontainer").innerHTML="<div id='rightslidebuttonleft'></div>";
		rightslideropen=true;
		}
		
	},
    contactForm: function(){
        $('.error').livequery(function(){
            $(this).hide();
        });
        $(".button").livequery(function(){
          $(this).click(function() {
            // validate and process form
            // first hide any error messages
            $('.error').hide();

            var name = $("input#name").val();
                if (name == "" || name == "το όνομά σας..") {
                    $("#nameError").fadeIn('fast');
                    $("input#name").focus();
                    return false;
                }
            var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
            var email = $("input#email").val();
                if (email == "" || email == "your email..") {
                    $("#emailError").fadeIn('fast');
                    $("input#email").focus();
                    return false;
                }
                else if (!emailReg.test(email) && !(email == "") && !(email == "email..")) {
                    $("#emailWrong").fadeIn('fast');
                    $("input#email").focus();
                    return false;
                }
            var message = $("textarea#message").val();
                if (message == "" && message.length < 8) {
                    if(message.length < 3)
                        $("#messageShort").fadeIn('fast');
                    else
                        $("#messageError").fadeIn('fast');
                    $("textarea#message").focus();
                    return false;
                }
            var dataString = 'name='+ name + '&email=' + email + '&message=' + message;
            $.ajax({
              type: "POST",
              url: "bin/processContactForm.php",
              data: dataString,
              success: function() {
                if (typeof(pageTracker) == "object")
                    pageTracker._trackPageview('/contactForm');
                $('#contactForma').html("<div id='feedback'><h3>Your message has been sent!</h3><p>We will contact you shortly.</p></div>");
              }
            });
            return false;
            });
        });
        $("input#name").livequery(function(){
            $(this).keypress(function (e){
                $("#nameError").fadeOut('slow');
            });
            $(this).blur(function() {
                $("#nameError").fadeOut('slow');
            });
        });
        $("input#email").livequery(function(){
            $(this).keypress(function (e){
                $("#emailError").fadeOut('slow');
                $("#emailWrong").fadeOut('slow');
            });
            $(this).blur(function() {
                $("#emailError").fadeOut('slow');
                $("#emailWrong").fadeOut('slow');
            });
        });
        $("textarea#message").livequery(function(){
            $(this).keypress(function (e){
                $("#messageShort").fadeOut('slow');
                $("#messageError").fadeOut('slow');
            });
            $(this).blur(function() {
                $("#messageShort").fadeOut('slow');
                $("#messageError").fadeOut('slow');
            });
        });
    },
	
	/****WORKING HERE***/
	    subscriptionForm: function(){
        $('.error').livequery(function(){
            $(this).hide();
        });
        $(".sButton").livequery(function(){  
          $(this).click(function() {
            // validate and process form
            // first hide any error messages
            $('.error').hide();

            var name = $("input#sName").val(); 
                if (name == "" || name == "το όνομά σας..") {
                    $("#sNameError").fadeIn('fast');
                    $("input#sName").focus();
                    return false;
                }
            var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
            var email = $("input#sEmail").val();
                if (email == "" || email == "your email..") {
                    $("#sEmailError").fadeIn('fast');
                    $("input#sEmail").focus();
                    return false;
                }
                else if (!emailReg.test(email) && !(email == "") && !(email == "email..")) {
                    $("#sEmailWrong").fadeIn('fast');
                    $("input#sEmail").focus();
                    return false;
                }

            var dataString =  'type=newslettersubscription' + '&name='+ name + '&email=' + email + '&message=' + "Please register me in your monthly newsletter.";
            $.ajax({
              type: "POST",
              url: "bin/processContactForm.php",
              data: dataString,
              success: function() {
                if (typeof(pageTracker) == "object")
                    pageTracker._trackPageview('/subscribeForm');
                $('#subscribeForma').html("<div id='sFeedback'><h3>Your registration request has been sent!</h3><p>From now on you will receive our monthly newsletter.</p></div>");
              }
            });
            return false;
            });
        });
        $("input#sName").livequery(function(){
            $(this).keypress(function (e){
                $("#sNameError").fadeOut('slow');
            });
            $(this).blur(function() {
                $("#sNameError").fadeOut('slow');
            });
        });
        $("input#sEmail").livequery(function(){
            $(this).keypress(function (e){
                $("#sEmailError").fadeOut('slow');
                $("#sEmailWrong").fadeOut('slow');
            });
            $(this).blur(function() {
                $("#sEmailError").fadeOut('slow');
                $("#sEmailWrong").fadeOut('slow');
            });
        });
    },
	
    init: function(){
        this.initializePage();
        this.contactForm();
		this.subscriptionForm();
    }
};


var currentRoom="";

var subnavigation = {
	subContent: function() {
		$('#subNavigation a, .extraSub').click(function() {
			var urlToLoad = $(this).attr('href').replace('html','php'); 
			var detailsToSee = 'siteContent/' + urlToLoad;
                var url = urlToLoad.substr(0,urlToLoad.length-4);
                window.location.hash = url == 'construction' ? 'constr' : url;		
                var secondContID = "#"+url;
                var $container = $('#secondaryContainer');
				var closeButton= document.getElementById('galleryCloserContainer');
                if ($(secondContID).length > 0 && $container.is(":visible")) {
                    $container.slideUp(700);
                }
                else if ($(secondContID).length > 0 && $container.is(":hidden")) {
                        subnavigation.scrolling($container);
						closeButton.style.visibility= "hidden"; //hide "x" button if studio gallery was shown previously
                }
                else {
                     $.ajax({
                       url: detailsToSee,
                       success: function(data){
                           $container.html(data);
                           subnavigation.scrolling($container); 
                           constGallery.fancy();
						   closeButton.style.visibility= "hidden"; //hide "x" button if studio gallery was shown previously
                       }   
                     });
                }
			return false;
		});
	},  
	scrolling: function(mover) {
		var docHeight    = $(document).height();
        $('html,body').animate({scrollTop: docHeight}, 1500);
        mover.fadeIn(1500);
	},
	init: function() {
		this.subContent();
	}
};


var studiogallery = {
	subContent: function() {
		$('a.studioGalleryLoader, .studioGalleryCloser').click(function() { 
			var urlToLoad = $(this).attr('href');
			var detailsToSee = 'siteContent/' + urlToLoad;
                var url= (urlToLoad.split('?'))[0]; //remove parameter list
				var room= (urlToLoad.split('?room='))[1]; //get current room to load;  
				
				url= url.substr(0, url.length-4); 
                window.location.hash = url == 'studioGallery' ? 'studioGal' : url;
                var secondContID = "#"+url;
                var $container = $('#secondaryContainer');				
				var closeButton= document.getElementById('galleryCloserContainer');
				
                if ($(secondContID).length > 0 && $container.is(":visible") && (currentRoom == room || room == "")) {
                    
					$container.slideUp(700);			
					closeButton.style.visibility= "hidden";
					currentRoom="";	
                }
				else if ($(secondContID).length > 0 && $container.is(":visible"))
				{
					   $.ajax({
                       url: detailsToSee,
                       success: function(data){
                           $container.html(data);
                           subnavigation.scrolling($container); 
                           constGallery.fancy();
						   closeButton.style.visibility= "visible";
						   currentRoom=room;
                       }
                     });
							
				}
               /* else if ($(secondContID).length > 0 && $container.is(":hidden")) { 
                        
						currentRoom=room;
						subnavigation.scrolling($container);
						closeButton.style.visibility= "visible";
						
                }*/
                else { 
                     $.ajax({
                       url: detailsToSee,
                       success: function(data){
                           $container.html(data);
                           subnavigation.scrolling($container); 
                           constGallery.fancy();
						   closeButton.style.visibility= "visible";
						   currentRoom=room;
                       }
                     });
                }
			return false;
		});
	},  
	scrolling: function(mover) {
		var docHeight    = $(document).height();
        $('html,body').animate({scrollTop: docHeight}, 1500);
        mover.fadeIn(1500);
	},
	init: function() {
		this.subContent();
	}
};



$(document).ready( function(){
    thisBrowser.browserDetect();
	
	if (thisBrowser.isIEOld) 
		{
			var ieText="The browser you are using may prevent fabricaudio.com from displaying properly."
			+"Please use one of the following browsers:<br/><br/><ul><li>Internet Explorer 7 or newer</li>"
			+"<li>Mozilla Firefox</li><li>Google Chrome</li><li>Opera</li><li>Apple Safari</li></ul>";
		    jQuery.IEfacebox(function() { 
            jQuery.IEfacebox(ieText);
			}); 
		}
	
	webStart.init();
	siteNavigation.init();
    smallMaps.smallMapFade();
    constGallery.init();
    subnavigation.init();
	studiogallery.init();
	toolTipPlease.makeToolTips('#toolTipTeam', '#teamTooltip', 260, '-125px', 500, 1);
	toolTipPlease.makeToolTips('#toolTipDirections', '#directionsTooltip', 250, '20px', 500, 1);
    toolTipPlease.makeToolTips('#toolTipGallery', '#galleryTooltip', 430, '590px', 500, 1);
    toolTipPlease.makeToolTips('#bookToContact', '#content_2', 145, '0', 500, 2, '#bookings');
	
	toolTipPlease.makeToolTips('#storageTip', '#storageRoom', '-50px', '-70px', 500, 1);
	
    toolTipPlease.makeToolTips('#tip1','#eq1', '-210px', '0px', 500, 1);
	toolTipPlease.makeToolTips('#tip2','#eq2', '-290px', '80px', 500, 1);

    toolTipPlease.makeToolTips('#tip3','#eq3', '-250px', '150px', 500, 1);
    toolTipPlease.makeToolTips('#tip4','#eq4', '-340px', '255px', 500, 1);
    toolTipPlease.makeToolTips('#tip5','#eq5', '-290px', '360px', 500, 1);
    toolTipPlease.makeToolTips('#tip6','#eq6', '-350px', '460px', 500, 1);

    toolTipPlease.makeToolTips('#tip7','#eq7', '-210px', '520px', 500, 1);
    toolTipPlease.makeToolTips('#tip8','#eq8', '-300px', '615px', 500, 1);
	
	
    var instanceOne = new ImageFlow();
	instanceOne.init({
        ImageFlowID: 'coverflow',
        startID:  5,
        imageCursor: 'pointer',
        onClick: function(){return false;}
    });
    $('.coverFlowItem').fancybox({
        'overlayShow':	true,
        'coverflow': true,
        'zoomSpeedIn': 300,
        'zoomSpeedOut': 300
	});
});

//to auto clear
jQuery.fn.clearFields = function (focusClass) {
    this.each(function () {
        $(this).focus(function () {
            // clear value if current value is the default
            if ($(this).val() === this.defaultValue) {
                $(this).val("");
            }
            // if focusClass is set, add the class
            if (focusClass) {
                $(this).addClass(focusClass);
            }
        }).blur(function () {
            // restore to the default value if current value is empty
            if ($(this).val() === "") {
                $(this).val(this.defaultValue);
            }
            // if focusClass is set, remove class
            if (focusClass) {
                $(this).removeClass(focusClass);
            }
        });
    });
};

/**
 * @author Alexander Farkas
 * v. 1.02
 */
(function($) {
	$.extend($.fx.step,{
	    backgroundPosition: function(fx) {
            if (fx.state === 0 && typeof fx.end == 'string') {
                var start = $.curCSS(fx.elem,'backgroundPosition');
                start = toArray(start);
                fx.start = [start[0],start[2]];
                var end = toArray(fx.end);
                fx.end = [end[0],end[2]];
                fx.unit = [end[1],end[3]];
			}
            var nowPosX = [];
            nowPosX[0] = ((fx.end[0] - fx.start[0]) * fx.pos) + fx.start[0] + fx.unit[0];
            nowPosX[1] = ((fx.end[1] - fx.start[1]) * fx.pos) + fx.start[1] + fx.unit[1];
            fx.elem.style.backgroundPosition = nowPosX[0]+' '+nowPosX[1];

           function toArray(strg){
               strg = strg.replace(/left|top/g,'0px');
               strg = strg.replace(/right|bottom/g,'100%');
               strg = strg.replace(/([0-9\.]+)(\s|\)|$)/g,"$1px$2");
               var res = strg.match(/(-?[0-9\.]+)(px|\%|em|pt)\s(-?[0-9\.]+)(px|\%|em|pt)/);
               return [parseFloat(res[1],10),res[2],parseFloat(res[3],10),res[4]];
           }
        }
	});
})(jQuery);




//custom animate because ie and chrome are crap with fadeing
(function($) {
	$.fn.customOpacity = function(level, speed, callback) {
        if(!thisBrowser.isIE && !thisBrowser.isChrome ){
            $(this).animate({'opacity': level}, function() {
                if(jQuery.browser.msie)
                    $(this).get(0).style.removeAttribute('filter');
                if(callback != undefined)
                    callback();
            },speed);
        }
	};
})(jQuery);

var thisBrowser = {
    browserDetect : function(){
        if (this.$bdetect)
            return;
        this.$bdetect = true;

        var sAgent = navigator.userAgent.toLowerCase();

        /**
         * Specifies whether the application is running in the Chrome browser.
         * @type {Boolean}
         */
        this.isChrome    = sAgent.indexOf("chrome/") != -1;

        var found;
        /**
         * Specifies whether the application is running in the Internet Explorer browser, any version.
         * @type {Boolean}
         */
        this.isIE        = document.all && !this.isOpera && !this.isSafari ? true : false;
        /**
         * Specifies whether the application is running in the Internet Explorer browser in version less than 7.
         * @type {Boolean}
         */
        this.isIEOld     = this.isIE && (found = true) && $.browser.version.substr(0,1) < 7;
        /**
         * Specifies whether the application is running in the Internet Explorer browser version 8.
         * @type {Boolean}
         */
        this.isIE8       = this.isIE && sAgent.indexOf("msie 8.") != -1 && (found = true);
        /**
         * Specifies whether the application is running in the Internet Explorer browser version 7.
         * @type {Boolean}
         */
        this.isIE7       = this.isIE && sAgent.indexOf("msie 7.") != -1 && (found = true);
        /**
         * Specifies whether the application is running in the Internet Explorer browser version 6.
         * @type {Boolean}
         */
        this.isIE6       = this.isIE && sAgent.indexOf("msie 6.") != -1 && (found = true);
        /**
         * Specifies whether the application is running in the Internet Explorer browser version 5.5.
         * @type {Boolean}
         */
        this.isIE55      = this.isIE && sAgent.indexOf("msie 5.5") != -1 && (found = true);
        /**
         * Specifies whether the application is running in the Internet Explorer browser version 5.0.
         * @type {Boolean}
         */
        this.isIE50      = this.isIE && sAgent.indexOf("msie 5.0") != -1 && (found = true);

    }
}