jQuery(document).ready(function() {

    // implementing css2.1 proprieties

    $('html').css({'overflow-y':'scroll'});
    $('.testimonial-content').css({'border-radius':'5px', '-moz-border-radius':'5px', '-webkit-border-radius':'5px'});
    $('#buba').css({'border-radius':'10px', '-moz-border-radius':'10px', '-webkit-border-radius':'10px'});
    /*$().css({});
    $().css({});*/

	jQuery(".testimonial-content p:first-child").addClass("first");
	jQuery("#text h3:first-child").addClass("first");
	jQuery(".testimonial-big:odd").addClass("odd");
	jQuery(".testimonial-content").each(function(){
			jQuery(this).find("p:last em").after('<img src="img/closeqotebig.gif" class="closequotebig" alt=" " />')
	});

    // Hover Butoane pt IE6.0
    if(/MSIE 6.0/.test(navigator.userAgent)){
         $('input.button').hover(
            function(){
		$(this).css("background-color", "#00A8FF");
	    },
	    function(){
		$(this).css("background-color", "#046E8C");
	    }
       );
    }

    if(typeof $('.team') == 'object'){
        $('.team img').each(function(i, item){
           $(this).wrap('<em></em>');
           $(this).parent().css({'position':'relative'});
           $('<img src="img/mask-thumb.png"/>').css({'position':'absolute', 'top':17, 'left':4, 'display': 'none'}).appendTo($(this).parent())

		   /*
           $(item).parent().hover(
               function(){
                 $(item).next().hide();
               },
               function(){
                 $(item).next().show();
               });
             */
        });
    }


	// Carousel portofoliu Home Page
    function mycarousel_initCallback(carousel){
    // Disable autoscrolling if the user clicks the prev or next button.
        carousel.buttonNext.bind('click', function() {
	    	carousel.startAuto(0);
	 	});
	    carousel.buttonPrev.bind('click', function() {
			carousel.startAuto(0);
		});

	    // Pause autoscrolling if the user moves with the cursor over the clip.
		carousel.clip.hover(function() {
			carousel.stopAuto();
		}, function() {
			carousel.startAuto();
		});

		setTimeout(function(){carousel.options.auto = 3;}, 2000);
	};

	if(typeof $('#mycarousel')[0] == 'object'){

	 // Initializare Carousel

	 jQuery('#mycarousel').jcarousel({
		 animation:500,
	     scroll: 1,
		 auto: 9,
		 wrap: 'last',
		 initCallback: mycarousel_initCallback
	 });

	 // afiseaza spanurile din carousel
	 $('#mycarousel li a span').css({'display':'block'});
		 //Incarca imaginile>5 dupa onload
		 var cnt = 500;
		 var cntFade = 2000;
			 $('ul#mycarousel li a img').each(function(i,item){
			 	/*if( i>3 &&  $(item).attr("class") != ""){ */
				setTimeout(function(){
					$(item).attr("src", $(item).attr("class"));
					setTimeout(function(){$(item).fadeIn(1000);}, 1000);
				}, cnt);
				cnt+=1000;
				/*}*/

				/*
				if (i >= 0 && i < 4) {
					setTimeout(function(){
						$(item).fadeIn(1000);
					}, cntFade);
					cntFade+=1000;
				}
				*/
	 });





	 // Hover detalii proiect
         $('#mycarousel li.jcarousel-item').each(function(i, item){
			 // IE6 nu suporta opacitatea pe elementele care au PNG transparent in background
             if(/MSIE 6.0/.test(navigator.userAgent)){
             	$(item)
					 .hover(
            	     function(){
        	             $(this).find('span').stop().animate({"bottom": "0"}, 350, 'easeOutQuad');
    	             },
	                 function(){
                    	 $(this).find('span').stop().animate({"bottom": "-85"}, 350, 'easeOutQuad');
                	 }
            	);
			}else{
				// !IE6.0
				$(item)
					 .hover(
            	     function(){
        	             $(this).find('span').stop().animate({"bottom": "0", "opacity": 1}, 350, 'easeOutQuad');
    	             },
	                 function(){
                    	 $(this).find('span').stop().animate({"bottom": "-55", "opacity": 0}, 350, 'easeOutQuad');
                	 }
            	).find('span').css("opacity", "0");
			}
         });
    }


	// Zona quotes FrontPage
	if (typeof $('#quotes')[0] == 'object') {

		$('#quotes .innerq div').css({
			'opacity': 0.8
		});

		var quotes = ['http://beta.innobyte.ro/img/quote2.png',
		              'http://beta.innobyte.ro/img/quote1.png',
					  'http://beta.innobyte.ro/img/quote2.png'];

		quotes.unshift($('#quotes .innerq img.quote')[0].src);
		randomQuotes.init(quotes);

	};


    // hover cariere
    $('div.projects div.project a').each(function(i, item){
	     // IE6 nu suporta opacitatea pe elementele care au PNG transparent in background
             if(/MSIE 6.0/.test(navigator.userAgent)){
             	$(item)
		.hover(
            	     function(){
        	             $(this).find('span').stop().animate({"bottom": "0"}, 250, 'easeOutSine');
    	             },
	             function(){
                    	     $(this).find('span').stop().animate({"bottom": "-45"}, 250, 'easeOutSine');
                     }
            	);
	    }else{
		// !IE6.0
		$(item)
		.hover(
		function(){
			$(this).find('span').stop().animate({"bottom": "0", "opacity": 1}, 250, 'easeOutSine');
		},
		function(){
			$(this).find('span').stop().animate({"bottom": "-45", "opacity": 0}, 250, 'easeOutSine');
		}
            ).find('span').css("opacity", "0");
	}
    });

    // Acordeon pagina cariere
    if(typeof $('#acordeon')[0] == 'object'){
         var items = $('#acordeon .item');
         var heights = [];

         $(items).each(function(i, item){
             var content = $(item).next();

             heights.push($(content)[0].offsetHeight);

			 $(content).css({"height":0});

             $(item).click(function(){

				 if(parseInt($(content).css("height")) > 0){
					 $(content).stop().animate({'height': 0}, 500, 'easeInOutSine');
				 }else{
					 $(items).each(function(j, prev){
    	                 if(parseInt($(prev).next().css("height")) > 0){
        	                 $(prev).next().stop().animate({'height': 0}, 500, 'easeInOutSine');
            	         }
                	 });

	                 $(this).next().stop().animate({'height': heights[i]}, 500, 'easeInOutSine');
				 }

             }).mouseover(function(){
                  if(/MSIE 6.0/.test(navigator.userAgent)){
                           $(this).css("cursor", "pointer");
                  }
             });
         });
    }

    // Lightbox Portofoliu si cariere
    if(typeof $('.contact-left')[0] == 'object'){
         $("a[rel^='prettyPhoto']").prettyPhoto({
                        animationSpeed: 'normal', /* fast/slow/normal */
                        padding: 40, /* padding for each side of the picture */
                        opacity: 0.35, /* Value betwee 0 and 1 */
                        showTitle: true, /* true/false */
                        allowresize: true, /* true/false */
                        counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */
                        theme: 'dark_rounded', /* light_rounded / dark_rounded / light_square / dark_square */
                        callback: function(){}
          });
    }

	// Lightbox Portofoliu si cariere
    if(typeof $('div.projects')[0] == 'object'){
         $("a[rel^='prettyPhoto']").prettyPhoto({
                        animationSpeed: 'normal', /* fast/slow/normal */
                        padding: 40, /* padding for each side of the picture */
                        opacity: 0.35, /* Value betwee 0 and 1 */
                        showTitle: true, /* true/false */
                        allowresize: true, /* true/false */
                        counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */
                        theme: 'dark_rounded', /* light_rounded / dark_rounded / light_square / dark_square */
                        callback: function(){}
          });
    }

    $('#cv')
    .css('opacity', '0.01')
    .change(function(){
	$('#cvmask').attr("value", $(this).attr('value'));
    })
    .hover(
    function(){
	    $(this).parent().find('input.button').css('background-color', '#00a8ff');
    },
    function(){
		$(this).parent().find('input.button').css('background-color', '#046e8c');
    });


    // formular upload cv
	if(typeof $('form#upload-cv')[0] == 'object' && !ERR){
		var cv = $('form#upload-cv #innercv');
		$(cv).css({'position':'absolute', 'left':0, 'bottom':0}).wrap('<div id="outercv" style="height:0;position:relative;overflow:hidden"><div>');
		var innerHeight = $(cv)[0].offsetHeight;
		$('a#show-upload').click(function(){

			// Efect Slide
			if(parseInt($('#outercv').css("height")) == innerHeight){
				$('#outercv').animate({"height":0}, 400);
			}else{
				$('#outercv').animate({"height":innerHeight}, 400);
			}

			/*
			// Efect Blind
			if($('form#upload-cv #innercv').css('height') == '145px'){
					$('form#upload-cv').animate({"height": "430px"});
				}else{
					$('form#upload-cv').animate({"height": "145px"});
				}
			*/
		return false;
		});
	}

}); /* end document ready  */

function toggleform() {
			if(parseInt($('#outercv').css("height")) == innerHeight){
				$('#outercv').animate({"height":0}, 400);
			}else{
				$('#outercv').animate({"height":innerHeight}, 400);
			}
}
function arata(id) {
		$("#testimoniale .sevede").fadeOut(400, function() {
			$("#testimoniale .sevede").removeClass("sevede");
			//$(".visible").removeClass("visible");
				$("#testimonial"+id).fadeIn(400, function () {
					$("#testimonial"+id).addClass("sevede");
					//$("#arata"+id).addClass("visible");
			});
		});
}



function sch(id,stop)
{
	if (id==stop) id=1;else id++;
	arata(id);
	try
	{
	clearTimeout(masa);
	}
	catch(e)
	{

	}
	masa=setTimeout("sch('"+id+"','"+stop+"')",12000);
}

var randomQuotes = {

	init: function(quotes){
		randomQuotes.slides = quotes;
		randomQuotes.prev = $('img#prevQ');
		randomQuotes.next = $('img#nextQ');
		randomQuotes.container = $('div#quotes div.innerq');
		randomQuotes.index = 0;
		randomQuotes.currentSlide = undefined;
		randomQuotes.setEvents();

	},

	setEvents: function(){

		$(randomQuotes.prev).click(function(){
			randomQuotes.fadeQuote(--randomQuotes.index);
		});
		$(randomQuotes.next).click(function(){
			randomQuotes.fadeQuote(++randomQuotes.index);
		});

		$(randomQuotes.container).hover(function(){
			randomQuotes.showArrows();
		}, function(){
			$('#quotes .innerq img#prevQ, #quotes .innerq img#nextQ').hide();
		});

	},

	fadeQuote: function(index){
	//alert(randomQuotes.index);
	    randomQuotes.showLoader();
		setTimeout(function(){
			randomQuotes.loadImage(randomQuotes.slides[index]);
		}, 500);

	},

	showLoader: function(){
		$(randomQuotes.container).find('img.loader, div').fadeIn(200);
		randomQuotes.showArrows();
	},

	hideLoader: function(){
		$(randomQuotes.container).find('img.loader, div').fadeOut(60);
	},

	showArrows: function(){
		if(randomQuotes.index > 0){
			$(randomQuotes.prev).show();
		}else{
			$(randomQuotes.prev).hide();
		}
		if(randomQuotes.index >= 0 && randomQuotes.index < randomQuotes.slides.length-1){
			$(randomQuotes.next).show();
		}else{
			$(randomQuotes.next).hide();
		}
	},

	loadImage: function(src){

        var newImg = new Image();
		var src = src;
        $(newImg).css("display", "none").appendTo(randomQuotes.container);


        if(/MSIE/.test(navigator.userAgent)){
            newImg.src = src;
            if (newImg.complete) {
        	    randomQuotes.hideLoader();
				setTimeout(function(){
					$(randomQuotes.container).find('img.quote').remove();
			 		$(newImg).addClass("quote").fadeIn(900, 'easeOutQuart');
				}, 40);
            }
            else {
                newImg.onload = function(){
	            randomQuotes.hideLoader();
				setTimeout(function(){
					$(randomQuotes.container).find('img.quote').remove();
			 		$(newImg).addClass("quote").fadeIn(900, 'easeOutQuart');
				}, 40);
                }
           }
        }else{
           newImg.onload=function(){
                newImg.src = src;
				randomQuotes.hideLoader();
				setTimeout(function(){
					$(randomQuotes.container).find('img.quote').remove();
			 		$(newImg).addClass("quote").fadeIn(900, 'easeOutQuart');
				}, 40);
                newImg.onload=function(){}; // clear onLoad, IE behaves irratically with animated gifs otherwise
           }
           newImg.src = src;
        }
		randomQuotes.currentSlide = newImg;
	}

};


function externalLinks() {
 if (!document.getElementsByTagName) return;
 var anchors = document.getElementsByTagName("a");
 for (var i=0; i<anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.getAttribute("href") &&
       anchor.getAttribute("rel") == "external")
     anchor.target = "_blank";
 }
}
window.onload = externalLinks;