

// Init Cufon
var int_cufon = function() {
    Cufon.replace('.bold', { fontFamily: 'Gotham Black', hover: true });
	Cufon.replace('.book', { fontFamily: 'Gotham-Book', hover: true });
	 
};



//Setting Menu Active
var int_menu = function() {   

    $( '.menu-item' ).hover( function(){ 
		var menuItem = $( this );  

        menuItem.find( '.submenu-container' ).css({ 
			'height': '0px', 'display': 'block' 
		}).stop().animate({
			'height': '300px'
		}, 400 );
		
	}, function(){
		var menuItem = $( this );
		menuItem.find( '.submenu-container' ).stop().animate({ 
			'height': '0px' 
		}, 200, function() {
			menuItem.find( '.submenu-container' ).hide();
		});
	}); 
    
    
    //Int Submit Call Validate
    $('#register-form input.submit').unbind().click(function(){
        validate_register(required_fields); 
    });
    $('#register-form input.close').unbind().click(function(){ 
        $('a#fancybox-close').trigger('click');
    });
};


// developer and advertiser slider
$.fn.slider = function(s, a, b, ajax){
    var $this = this;  
    $this.unbind().click(function(e){   
        var $_this = $(this).parents('.imgbox').parent();
        var pointer = $(this).attr('ref'); 
        if(ajax) {
            $('#infoCon').fadeOut(300);
            callback_ajax(pointer, 0);
        }
        $_this.find('.tabbox .iconbox').hide();   
        $_this.find('.tabbox .iconbox.note_' + pointer).show();
        $_this.find('.tabbox').animate({left: ((s * pointer) - s) + a +  'px'});
        $_this.find('.arrowbox').animate({left: ((s * pointer) - s) + b +  'px'});  
    }); 
}; 


// news
var callback_ajax = function(f, p){
    $.ajax({
            type: "GET",
			url: '_ajax_news.php',
			data: ({
			     'page': p,
                 'ref': f
                 }),
			success: function(msg){
			    $('#infoCon').hide().html(msg).fadeIn(300);
			    int_cufon();
                int_pager();
                int_more();
                setPageHeight();
			}
        });
    return false;
};
var int_more = function(){
    $('.expandclick').unbind().click(function(){  
		var parent = $(this).parents('li.list');  
            $('.conBody').slideUp();
            $('.expandclick').show();
            $(this).hide();
			parent.find('.conBody').slideDown(300, function(){setPageHeight()});  
	});
	$(".arrowup").unbind().click(function(){  
	    var parent = $(this).parents('li.list');  
			parent.find('.conBody').slideUp();
			parent.find('.expandclick').show(300, function(){setPageHeight()});
	});		  
};
var int_pager = function(){
    $('a.pager').unbind().click(function(e){ 
        empty(e);
        if(!$(this).hasClass('current')) {
            var ref=$(this).attr('ref');
            var page=$(this).attr('rel') - 1; 
            $('#infoCon').fadeOut(300);
            callback_ajax(ref, page);   
            $('html, body').animate({
                scrollTop: $("#press-box").offset().top
            }, 1000);
        }
    });
};
//Return Empty Link
var empty = function(e) {
    e.preventDefault();
    e.stopPropagation(); 
};



// set page height
function setPageHeight() {

    var contentHeight = $( '.content-container' ).height();
    var windowHeight = $( 'html' ).height();
    var headerHeight = $('.carousel-bg').height();

    // to content height
    if( contentHeight > windowHeight ) {
       if($('body.allgames').length || $('body.home').length) {
           contentHeight += 130;
       }
        $( '#page' ).height( contentHeight );
        $( '.content-bg' ).height( contentHeight );
        $( '.content-bg div:nth-child(2)' ).height( contentHeight - headerHeight );
        $( '#page .content-border-right, #page .content-border-left').height( contentHeight );
    }

    // or if content is smaller than the window set height to window
    else {
        $( '#page' ).height( windowHeight );
        $( '.content-bg' ).height( windowHeight );
    }
}

//Check Valid Email
var email = function(value) {
    var emailExp  = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+[\.]{1}[a-zA-Z]{2,4}$/;  
    return (emailExp.test(value)) ? 0 : 1;  
};

//Check Valid Email & Required
var requireEmail = function(value) { 
    var req = require(value, 0);  
    var em = email(value);   
    if(req) return req;
    if(em) return em;
};
var isAlphabet = function(value){
	var alphaExp = /^[a-zA-Z]+$/; 
    return (value.match(alphaExp) && value) ? 0 : 1;  
};
//Check Field Required
var require = function(value, isAplhabet) {
    if(isAplhabet > 0)
        return isAlphabet(value);
    else
        return (value) ? 0 : 1;
};

var validate_contact = function(){

    
    var err = 0;  
    if($('#adForm').is(':visible')) {   
        //List of required fields for register page
        var advert_fields = [
            "title",
            "first_name",
			"last_name",
            "email",
            "state",
            "industry",
            "country",
            "zip",
            "budget"
        ];
        //$('#adForm .errors').removeClass('special').hide(); //Reset Cufon Style
        $('#adForm .inputBox').removeClass('high'); //Reset BOrder Color 
        $.each(advert_fields, function(k, v) {  
             if(v == 'email') {
                var email = requireEmail($("#adForm input[name="+v+"]").val()); 
                if(email == 1) {
                    $("#adForm input[name="+v+"]").addClass('high');
                    //$('#adForm .errors.' + v).show();
                    err++;
                } 
             }
             else if(v == 'industry') {
                var sel = require($("#adForm select[name="+v+"]").val(), 0); 
                if(sel == 1) {
                    $("#adForm select[name="+v+"]").addClass('high');
                    //$('#adForm .errors.' + v).show(); 
                    err++;
                } 
             } 
             else { 
                var value = require($("#adForm input[name='"+v+"']").val(), 0);   
                if(value == 1) {
                    $("#adForm input[name='"+v+"']").addClass('high');
                    //$('#adForm .errors.' + this).show();
                    err++;
                } 
             }
        }); 
    }
    
    if($('#devForm').is(':visible')) {   
        //List of required fields for register page
        var dev_fields = [
            "title",
            "first_name",
			"last_name",
            "email",
            "state",
            "address",
            "00N40000002QubD",
            "00N40000002Qub8",
            "00N40000002QubI",
            "zipcode"
        ];
        //$('#devForm .errors').removeClass('special').hide(); //Reset Cufon Style
        $('#devForm .inputBox').removeClass('high'); //Reset BOrder Color 
        $.each(dev_fields, function(k, v) {  
             if(v == 'email') {
                var email = requireEmail($("#devForm input[name="+v+"]").val()); 
                if(email == 1) {
                    $("#devForm input[name="+v+"]").addClass('high');
                    //$('#devForm .errors.' + v).show();
                    err++;
                } 
             }
             else if(v == 'industry') {
                var sel = require($("#devForm select[name="+v+"]").val(), 0); 
                if(sel == 1) {
                    $("#devForm select[name="+v+"]").addClass('high');
                    //$('#devForm .errors.' + v).show(); 
                    err++;
                } 
             } 
             else { 
                var value = require($("#devForm input[name='"+this+"']").val(), 0);   
                if(value == 1) {
                    $("#devForm input[name='"+v+"']").addClass('high');
                    //$('#devForm .errors.' + this).show();
                    err++;
                } 
             }
        }); 
    }
    if(err > 0) {  
        //$('#adForm .errors').addClass('special');
        //int_cufon();
        return false;
    }else {
        return true;
    } 
};









