/*
 * Author   : Muharrem ERİN
 * Corp     : MeWebStudio
 * Web      : mewebstudio.com
 * Mail     : me@mewebstudio.com
 * Date     : 2011/07/06
 * Copyright (c) 2011
 *
 */

$(window).load(function(){

    /* menu */
    $('#header .bottom .mask').css({ 'opacity':'0.5' });
    $('#header .bottom .menu ul.items li.home a span').html('');
    $('#header .bottom .menu ul.items').dropmenu();
    $('#header .bottom .menu ul.items li').hover(function(){
	$(this).children('a').addClass('hover');
    }, function(){
	$(this).children('a').removeClass('hover');
    });

    /* slider */
    $('#slider').nivoSlider();

    /* input text manipulations */
    $('input[type="text"], textarea').css({ 'color':'#949494', 'font-style':'italic' });
    $('input[type="text"], textarea').focus(function() {
        if (this.value == this.defaultValue){ 
            this.value = '';
            $(this).css({ 'color':'#4b4b4b', 'font-style':'normal' });
	}
	if (this.value != this.defaultValue){
            this.select();
	}
    });
    $('input[type="text"], textarea').blur(function() {
        if ($.trim(this.value) == ''){
            this.value = (this.defaultValue ? this.defaultValue : '');
            $(this).css({ 'color':'#949494', 'font-style':'italic' });
        }else{
            $(this).css({ 'color':'#4b4b4b', 'font-style':'normal' });
        }
    });

    /* external links */
    $('a.external').click(function(){
	window.open($(this).attr('href'));
	return false;
    });

    /* header search form */
    $('#header .bottom .menu form.search').submit(function(){
	var k_val = $('#header .bottom .menu form.search input.text').val();
	if (k_val != '')
	{
	    document.location.href = basePATH+'products/search?k='+k_val;
	}
	return false;
    });

    /* embed font ie hack */
    $('#middle .ptitle .fright h2').ieffembedfix();

    /* subscribe box */
    $('#middle .main .subscribe .fmiddle .box').css({ 'opacity':'0.6' });
    $('#middle .main .subscribe .fmiddle form').submit(function(){
	$('#middle .main .subscribe .fmiddle .box').addClass('loading').show('fast');
	$.ajax({
	    type: 'GET',
	    url: basePATH + 'ajax/sucscribe',
	    data: 'name='+$('#middle .main .subscribe .fmiddle form input[name="name"]').val()+'&mail='+$('#middle .main .subscribe .fmiddle form input[name="mail"]').val(),
	    success: function(response) {
                $('#middle .main .subscribe .fmiddle .box').removeClass('loading');
                $('#middle .main .subscribe .fmiddle .box p').html(response).show('fast');
	    }
	});
        return false;
    });
    $('#middle .main .subscribe .fmiddle .box a.close').click(function(){
	$('#middle .main .subscribe .fmiddle .box p').html('');
	$('#middle .main .subscribe .fmiddle .box').hide('fast');
        return false;
    });

    /* products item */
    $('#middle .page .products .item').children('.image, a').stop().animate({ 'opacity': '0.6' }, 0);
    $('#middle .page .products .item').hover(function(){
	$(this).addClass('hover');
	$(this).children('h3').css({ 'text-decoration':'underline' });
	$(this).children('.image, a').stop().animate({
	    'opacity': '1'
	}, 500);
    }, function(){
	$(this).removeClass('hover');
	$(this).children('h3').css({ 'text-decoration':'none' });
	$(this).children('.image, a').stop().animate({
	    'opacity': '0.6'
	}, 500);
    });
    $('#middle .page .products .item').click(function(){
	document.location.href = $(this).children('a').attr('href');
    });
    $('#middle .page .product_view .btn a.properties').click(function(){
	$('#middle .page .product_view .view').slideToggle('fast');
	return false;
    });
    $('#middle .page .product_view .btn a.timages').click(function(){
	$('#middle .page .product_view .images-t').slideToggle('fast');
	return false;
    });

    /* products images */
    $('#middle .page .product_view .images a').stop().animate({ 'opacity': '0.6' }, 0);
    $('#middle .page .product_view .images a').hover(function(){
	$(this).stop().animate({
	    'opacity': '1'
	}, 300);
    }, function(){
	$(this).stop().animate({
	    'opacity': '0.6'
	}, 300);
    });

    /* colorbox */
    $('a[rel="colorbox"], a[rel="colorbox2"]').colorbox();

    /* contact form */
    $('#middle .page .content .form form').submit(function(){
        $('#middle .page .content .form p.message').css('color', '#444444').html('Gönderiliyor, lütfen bekleyiniz...');
	$.ajax({
	    type: 'GET',
	    url: basePATH + 'ajax/contact',
	    data: 'name='+$('#cf_name').val()+'&mail='+$('#cf_mail').val()+'&phone='+$('#cf_phone').val()+'&subject='+$('#cf_subject').val()+'&message='+$('#cf_message').val(),
	    success: function(response) {
		if ($('#cf_name').val() == '' || $('#cf_mail').val() == '' || $('#cf_subject').val() == '' || $('#cf_message').val() == '')
		{
		$('#middle .page .content .form p.message').css('color', '#ff3300').html(cftext);
		    $('#middle .page .content .form form').css('display', 'block');
		}
		else
		{
			 $('#middle .page .content .form form').css('display', 'none');
		    $('#middle .page .content .form p.message').css('color', '#6e8801').html(cfsend);
			}
		
		
		/*if (response == 0)
                {
                    $('#middle .page .content .form p.message').css('color', '#ff3300').html(cftext);
		    $('#middle .page .content .form form').css('display', 'block');
                }
               if (response == 1)
                {
		    $('#middle .page .content .form form').css('display', 'none');
		    $('#middle .page .content .form p.message').css('color', '#6e8801').html(cfsend);
                } */
	    }
	});
        return false;
    });

});
