
$(document).ready(function() {
	
	$(".main_what_we_do	.item").hover(function() { //On hover...
		
		var thumbOver = $(this).find("img").attr("src"); //Get image url and assign it to 'thumbOver'
		
		$(this).find("div.thumb").css({'background' : 'url(' + thumbOver + ') no-repeat center bottom'});
		//Fade the image to 0 
		$(this).find("span").stop().fadeTo('normal', 0 , function() {
			$(this).hide() //Hide the image after fade
		}); 
	} , function() { //on hover out...
		//Fade the image to 1 
		$(this).find("span").stop().fadeTo('normal', 1).show();
	});
    
    try
    {
        $("#main_work").scrollable({circular: true, mousewheel: false}).navigator().autoscroll({ autoplay: true, interval: 2500 });
        $("#main_news").scrollable({circular: true, mousewheel: false}).navigator();
        $("#main_products").scrollable({circular: true, mousewheel: false}).navigator();
    }catch(err){}
    
    $(".main_work a").hover(function(){
        $(this).children("span").fadeOut();
    },function(){
        $(this).children("span").fadeIn();
    });
    
    try
        {
        $('.slideshow').cycle({
            fx: 'fade',
            timeout: 6000,
            speed: 1000,
			pause: true,
            next:'#next',
            prev:'#prev'
        });
    }catch(err){} 
	
	$('a[rel*=external]').click( function() {
        window.open(this.href);
        return false;
    });

});
	
function switch_divs(show_div,hide_div){
	
	$('#'+hide_div).hide();
	$('#'+show_div).fadeIn();

}

function __in(divID){
	$(divID).fadeIn();
}

function __out(divID){
	$(divID).fadeOut();
	
}
							
function yourTurn(form,_url){	
	$("#msg").hide();
	$("#buttons").hide();
	$("#loading_ani").show(); 

	$.ajax({
		type: "POST",
		url: _url,
		data : $("#"+form).serialize(),
		success: function(html){
			var r = html.split("|");
			$("#buttons").show();
			$("#loading_ani").hide(); 
			
			if(r[0] == 1){
				$("#name").val('');
				$("#email").val('');
				$("#message").val('');	
				$("#phone").val('');
				$("#countryID").val('');
                
               window.location = $("#thankyou_url").val();
			}
			$("#security_code").val('');	
			jumpTo('#id_yourturn'); 
			$("#msg").show();
			$("#msg").html(r[1]);
			$("#q").html(r[2]);
		}
	});
}

function subscribe_foot(form,_url){	
	$("#newsletter_msg").hide();


	if($("#foot_name").val() == "Name" || $.trim($("#foot_name").val()) == ""){
		$("#newsletter_msg").show();
		$("#newsletter_msg").html("<p style='color:red;'>Name required</p>");
		return;
	}
	
	if($("#foot_email").val() == "E-mail" || $.trim($("#foot_email").val()) == ""){
		$("#newsletter_msg").show();
		$("#newsletter_msg").html("<p style='color:red;'>Email required</p>");
		return;
	}
	
	$("#newsletter_msg").hide();
	$.ajax({
		type: "POST",
		url: _url,
		data : $("#"+form).serialize(),
		success: function(html){
			var r = html.split("|");
			if(r[1] == 1){
				$("#div_get_yourself_posted").hide();
			}
			$("#newsletter_msg").show();
			$("#newsletter_msg").html(r[2]);
		}
	});
}

var current_div_section = '';
function mToggle(divID){
	if(current_div_section != divID){
		$(".toggle_section").slideUp();
	}
	$(divID).slideToggle('slow');
	current_div_section = divID;
}

function jumpTo(divID){
	var target = $(divID);
	target = target.length && target
	var targetOffset = target.offset().top;
	$("html,body").animate({scrollTop: targetOffset}, 1000);
}

function showImage(_url,imageID,portfolioid){
	_data = "imageID="+imageID + "&portfolioid="+portfolioid;
	$.ajax({
		type: "POST",
		url: _url,
		data: 	_data ,
		success: function(html){

			var r = html.split("|");
			var status = parseInt(r[0]);
			var img = r[1];
			var portfolioID = parseInt(r[2]);  
	
			if(status == 1){
				$("#desc_"+portfolioID).css("visibility", "hidden");
				$("#img_display_"+portfolioID).hide();
				$("#img_display_"+portfolioID).html(img);
				$("#img_display_"+portfolioID).show('slow');
			}
		}
	});
}

function _visible(divID){
	$(divID).css("visibility", "visible");
}

function _invisible(divID){
	$(divID).css("visibility", "hidden");
}

function _hint(obj,target_value,onblur){
	if(obj.value == target_value){
		obj.value = '';	
	}
	
	if(onblur == 1 && $.trim(obj.value) == ''){
		obj.value = target_value;
	}
}

function redirect(_url){
	window.location = _url;
}

function validate_rfp_form(form){
	var is_error = false;
	if($.trim(form.name.value) == ''){
		$("#em_name").show();
		is_error = true;
	}
	
	if($.trim(form.email.value) == ''){
		$("#em_email").show();
		is_error = true;
	}else if(!validate_email(form.email.value)){
		$("#em_email").show();
		("#em_email").html("Invalid email address");
		is_error = true;
	}
	
	if($.trim(form.phone.value) == ''){
		$("#em_phone").show();
		is_error = true;
	}
	
	
	if($.trim(form.countryID.value) == ''){
		$("#em_countryID").show();
		is_error = true;
	}
	
	if(is_error){
		$("#jmp_rfp_form").show();
		jumpTo('#rfp_jump');
		return false;
	}
	$("#jmp_rfp_form").hide();
	return true;
}
