/*
 * 
 * Rockpirat js inits
 * 
 * 
 * */




$(document).ready(function(){
	
	
	
	// Pretty Photo Lightbox
	
	$("a[rel^='prettyPhoto']").prettyPhoto({
					theme: 'dark_square',
					show_title: false,
					animation_speed: 'normal'
	});
	
	
	//Twitter
	
	$(".twitter_wrapper").getTwitter({
					userName: "rockpirat",
					numTweets: 3,
					loaderText: "Lade Tweets...",
					slideIn: false,
					slideDuration: 750,
					showHeading: false,
					headingText: "",
					showProfileLink: false,
					showTimestamp: true
				});
	
	//Band Start
	
	
	//Custom settings  
    var style_in = 'easeOutBounce';  
    var style_out = 'jswing';  
    var speed_in = 1000;  
    var speed_out = 300;      
  
    //Calculation for corners  
    var neg = Math.round($('.qitem').width() / 2) * (-1);     
    var pos = neg * (-1);     
    var out = pos * 2;  
      
    $('.qitem').each(function () {  
      
        //grab the anchor and image path  
        url = $(this).find('a').attr('href');  
        img = $(this).find('img').attr('src');  
          
        //remove the image  
        $('img', this).remove();  
          
        //append four corners/divs into it  
        $(this).append('<div class="topLeft"></div><div class="topRight"></div><div class="bottomLeft"></div><div class="bottomRight"></div>');  
          
        //set the background image to all the corners  
        $(this).children('div').css('background-image','url('+ img + ')');  
  
        //set the position of corners  
        $(this).find('div.topLeft').css({top:0, left:0, width:pos , height:pos});     
        $(this).find('div.topRight').css({top:0, left:pos, width:pos , height:pos});      
        $(this).find('div.bottomLeft').css({bottom:0, left:0, width:pos , height:pos});   
        $(this).find('div.bottomRight').css({bottom:0, left:pos, width:pos , height:pos});    
  
    }).hover(function () {  
      
        //animate the position  
        $(this).find('div.topLeft').stop(false, true).animate({top:neg, left:neg}, {duration:speed_out, easing:style_out});   
        $(this).find('div.topRight').stop(false, true).animate({top:neg, left:out}, {duration:speed_out, easing:style_out});      
        $(this).find('div.bottomLeft').stop(false, true).animate({bottom:neg, left:neg}, {duration:speed_out, easing:style_out});     
        $(this).find('div.bottomRight').stop(false, true).animate({bottom:neg, left:out}, {duration:speed_out, easing:style_out});    
                  
    },  
      
    function () {  
  
        //put corners back to the original position  
        $(this).find('div.topLeft').stop(false, true).animate({top:0, left:0}, {duration:speed_in, easing:style_in});     
        $(this).find('div.topRight').stop(false, true).animate({top:0, left:pos}, {duration:speed_in, easing:style_in});      
        $(this).find('div.bottomLeft').stop(false, true).animate({bottom:0, left:0}, {duration:speed_in, easing:style_in});   
        $(this).find('div.bottomRight').stop(false, true).animate({bottom:0, left:pos}, {duration:speed_in, easing:style_in});    
      
    }).click (function () {  
          
        //go to the url  
        //window.location = $(this).find('a').attr('href');     
    });    
	
	
	//Band End
	
	// // Tab Navigation Simple Version
	//var settings = { start:1, change:false }; 
	//$("#navigation ul").idTabs(settings,true); 
	
	
	// // Tab Navigation FX Version !!!! muss als letzte Funktion stehen, sonst bandbilder slice bug
	$("#navigation_area").idTabs(function(id,list,set){ 
    $("a",set).removeClass("selected") 
    .filter("[href='"+id+"']",set).addClass("selected"); 
	Cufon.refresh();	// fix hover Bug - Farbe wurde nicht aktualisiert
    for(i in list) 
      $(list[i]).hide(); 
    $(id).fadeIn({
		speed: 1000
	}); 	
    return false; 
  	}); 
	
	
	
	//Contactform
	
	$('#send_message').click(function(e){
           
            //stop the form from being submitted
            e.preventDefault();
            
            /* declare the variables, var error is the variable that we use on the end
            to determine if there was an error or not */
            var error = false;
            var name = $('#name').val();
            var email = $('#email').val();
            var subject = $('#subject').val();
            var message = $('#message').val();
            
            /* in the next section we do the checking by using VARIABLE.length
            where VARIABLE is the variable we are checking (like name, email),
            length is a javascript function to get the number of characters.
            And as you can see if the num of characters is 0 we set the error
            variable to true and show the name_error div with the fadeIn effect. 
            if it's not 0 then we fadeOut the div( that's if the div is shown and
            the error is fixed it fadesOut. 
            
            The only difference from these checks is the email checking, we have
            email.indexOf('@') which checks if there is @ in the email input field.
            This javascript function will return -1 if no occurence have been found.*/
            if(name.length == 0){
                var error = true;
                $('#name_error').fadeIn(500);
            }else{
                $('#name_error').fadeOut(500);
            }
            if(email.length == 0 || email.indexOf('@') == '-1'){
                var error = true;
                $('#email_error').fadeIn(500);
            }else{
                $('#email_error').fadeOut(500);
            }
            if(subject.length == 0){
                var error = true;
                $('#subject_error').fadeIn(500);
            }else{
                $('#subject_error').fadeOut(500);
            }
            if(message.length == 0){
                var error = true;
                $('#message_error').fadeIn(500);
            }else{
                $('#message_error').fadeOut(500);
            }
            
            //now when the validation is done we check if the error variable is false (no errors)
            if(error == false){
                //disable the submit button to avoid spamming
                //and change the button text to Sending...
                $('#send_message').attr({'disabled' : 'true', 'value' : 'Nachricht senden ...' });
                
                /* using the jquery's post(ajax) function and a lifesaver
                function serialize() which gets all the data from the form
                we submit it to send_email.php */
                $.post("send_email.php", $("#contact_form").serialize(),function(result){
                    //and after the ajax request ends we check the text returned
                    if(result == 'sent'){
                        //if the mail is sent remove the submit paragraph
                         $('#cf_submit_p').remove();
                        //and show the mail success div with fadeIn
                        $('#mail_success').fadeIn(500);
                    }else{
                        //show the mail failed div
                        $('#mail_fail').fadeIn(500);
                        //reenable the submit button by removing attribute disabled and change the text back to Send The Message
                        $('#send_message').removeAttr('disabled').attr('value', 'Nachricht versenden');
                    }
                });
            }
        }); 
		
	
});

// Big BG Image !!! Aufruf zuletzt, sonst kein resize
$(function() {	

	/*
    // Options for SuperBGImage
    $.fn.superbgimage.options = {
        randomtransition: 0, // 0-none, 1-use random transition (0-7)
        slideshow: 0, // 0-none, 1-autostart slideshow
        slide_interval: 6000, // interval for the slideshow
        randomimage: 1, // 0-none, 1-random image
        speed: 1000, // animation speed
        preload: 1
    };
    */
 
    // initialize SuperBGImage
    $('#superbgimage').superbgimage().hide();
	
	// click on Navigation shows next SuperBGImage
	/*
	$('a.next').click(function() {
	return $('#superbgimage').nextSlide();
	});
 	*/
	
	

	

});

 
 


 
 	
