var base_url = "http://arox-doo.com/";

$(function() {
    $('#footer_image a').lightBox();
	$('#footer_image_last a').lightBox();
});

//document start function
$(document).ready(function(){
$('#search').keypress(function(e) { if (e.keyCode == '13') { e.preventDefault(); changeview(base_url+"pretraga/"+document.getElementById('search').value);}});
$('#newsletter').keypress(function(e) { if (e.keyCode == '13') { e.preventDefault(); newsletter();}});

//banner
$('ul#portfolio').innerfade({
				speed: 1000,
				timeout: 5000,
				type: 'random',
				containerheight: '220px'
});




/*
$('#main').height($(window).height());
//$('#footer').height($(window).height()-$('#header_top').height()-$('#header_bottom').height()-('#navi').height()-('#banner').height()-$('#middle').height());
//alert($(window).height());
//
//footer allwys down
//$('#copyright').css("position","absolute");
//$('#copyright').css("top", new_height); 
$('#footer').height(Math.ceil($(window).height()-$('#header_top').height()-$('#header_bottom').height()-$('#navi').height()-$('#banner').height()-$('#middle').height()-30));

alert($(window).height()-$('#header_top').height());

*/


/*banner
var autoPlayTime=3000;
	autoPlayTimer = setInterval( autoPlay, autoPlayTime);
	function autoPlay(){
		
		Slidebox('next');
	}
	$('#slidebox .next').click(function () {
		Slidebox('next','stop');
	});
	$('#slidebox .previous').click(function () {
		Slidebox('previous','stop');
	});
	var yPosition=($('#slidebox').height()-$('#slidebox .next').height())/2;
	$('#banner #slidebox .next').css('top',yPosition);
	$('#slidebox .previous').css('top',yPosition);
	$('#slidebox .thumbs a:first-child').removeClass('thumb').addClass('selected_thumb');
	$("#slidebox .content").each(function(i){
		slideboxTotalContent=i*$('#slidebox').width();	
		$('#slidebox .container').css("width",slideboxTotalContent+$('#slidebox').width());
	});
});
*/
});

//check email 
function validate_email(email) {
 
  var reg =   /^[^@]+@[^@]+.[a-z]{2,}$/;
   var address = email;
   if(reg.test(address) == false) 
      return false;
	  return true;
}


/*show messge*/
function jsMessage(message){
	$('#message').css("position","absolute");
    $('#message').css("top", (($(window).height() - $('#message').height()) / 2) + $(window).scrollTop() + "px");
    $('#message').css("left", (($(window).width() - $('#message').width()) / 2) + $(window).scrollLeft() + "px");
    $('#message').html(message).show();
	
}
/*close message*/
function jsMessageClose(){
    $('#message').hide();
}


/*newsletters*/
function newsletter(){
	var email = $("#newsletter").val();
	if(!email){
		 jsMessage('<br><br>Niste unijeli Vaš email.');setTimeout("jsMessageClose()",2000);	 
		 $("#newsletter").focus();
	}else{
		
	if(validate_email(email)){
       $.post( base_url+"mod/newsletters/prijava.php",{
					email: email
					},
					function(res){
					if(res.success) {
					  jsMessage('Uspiješno ste se prijavili.<br><br>Uskoro ćemo Vas obavijestiti o najnovijim informacijama o našem poslovanju.');setTimeout("jsMessageClose()",5000);
					}else{
					  jsMessage('<br><br>'+res.mail+'');setTimeout("jsMessageClose()",2000);
					}
					$("#newsletter").val('');
					},'json');
	}else{
		jsMessage('<br><br>Neispravan email. Pokušajte ponovo');setTimeout("jsMessageClose()",2000);
	}
  }
}			




function show_proizvod(id){

 $('#proizvod_info'+id).animate({bottom: '1'},100);


}

function hide_proizvod(id){

 $('#proizvod_info'+id).animate({ bottom: '-45' }, 100);
	
}


function changeview(href){
	
 window.location.href = href;
 
}
/*
$(document).ready(function() {
	
});
*/

function Slidebox(slideTo,autoPlay){
    var animSpeed=1000; //animation speed
    var easeType='easeInOutExpo'; //easing type
	var sliderWidth=$('#slidebox').width();
	var leftPosition=$('#slidebox .container').css("left").replace("px", "");
	if( !$("#slidebox .container").is(":animated")){
		if(slideTo=='next'){ //next
			if(autoPlay=='stop'){
				clearInterval(autoPlayTimer);
			}
			if(leftPosition==-slideboxTotalContent){
				$('#slidebox .container').animate({left: 0}, animSpeed, easeType); //reset
				$('#slidebox .thumbs a:first-child').removeClass('thumb').addClass('selected_thumb');
				$('#slidebox .thumbs a:last-child').removeClass('selected_thumb').addClass('thumb');
			} else {
				$('#slidebox .container').animate({left: '-='+sliderWidth}, animSpeed, easeType); //next
				$('#slidebox .thumbs .selected_thumb').next().removeClass('thumb').addClass('selected_thumb');
				$('#slidebox .thumbs .selected_thumb').prev().removeClass('selected_thumb').addClass('thumb');
			}
		} else if(slideTo=='previous'){ //previous
			if(autoPlay=='stop'){
				clearInterval(autoPlayTimer);
			}
			if(leftPosition=='0'){
				$('#slidebox .container').animate({left: '-'+slideboxTotalContent}, animSpeed, easeType); //reset
				$('#slidebox .thumbs a:last-child').removeClass('thumb').addClass('selected_thumb');
				$('#slidebox .thumbs a:first-child').removeClass('selected_thumb').addClass('thumb');
			} else {
				$('#slidebox .container').animate({left: '+='+sliderWidth}, animSpeed, easeType); //previous
				$('#slidebox .thumbs .selected_thumb').prev().removeClass('thumb').addClass('selected_thumb');
				$('#slidebox .thumbs .selected_thumb').next().removeClass('selected_thumb').addClass('thumb');
			}
		} else {
			var slide2=(slideTo-1)*sliderWidth;
			if(leftPosition!=-slide2){
				clearInterval(autoPlayTimer);
				$('#slidebox .container').animate({left: -slide2}, animSpeed, easeType); //go to number
				$('#slidebox .thumbs .selected_thumb').removeClass('selected_thumb').addClass('thumb');
				var selThumb=$('#slidebox .thumbs a').eq((slideTo-1));
				selThumb.removeClass('thumb').addClass('selected_thumb');
			}
		}
	}
}
