// JavaScript Document
///\brief Functions launched when DOM is ready

$(document).keydown(function(e) {
							
	var element = e.target.nodeName.toLowerCase();
	if (element == 'input' || element == 'textarea') {
		if (e.keyCode ===220) {
			return false;
		}
	}
});
	/* ----- Consent cookie , not for Turkey, Russia, Ukraine and Kazakhstan------- */	
jQuery(document).ready(function($)  {
								
			if(showPopupCookie()){										
					if($.fancybox){			
						if($.cookie('consent.cookie')== null ){					
									$.fancybox.init();
									$.fancybox({'width': 470,'height':320,'autoScale':false,'transitionIn':'none','modal':true,'transitionOut':'none','type':'iframe','href': '/support/'+ currentlocale.substring(0,2) +'/consent-cookie' });									
						}						
					}
			}
	/* -----End  Consent cookie -------- */											  
	   });

$(function () {
		
		/* ----------to format picture on product page-----------------*/
	if($("#productimg").length){
			var h = $("#productimg").height();
			var w = $("#productimg").width();
			if ( h > w ){			
			$("#productimg").removeClass('landscape').addClass('portrait');			
			}				
	}
		  
		  if($("iframe").length){ 
			 /*console.log( $('div#tabpage iframe').height());*/
			  //console.log( $('iframe html').length());
			  
		  }
		  
	if ($('#pc').length != '0') {
		var pc = $.cookie('productCode') ? $.cookie('productCode') : '';
		var sn = $.cookie('serialNumber') ? $.cookie('serialNumber') : '';
		var mn = $.cookie('modelId') ? $.cookie('modelId') : '';
		var model = $.cookie('modelname') ? $.cookie('modelname') : '';
		
		if(sn!=''){$('#sn').val(sn);}
		if(pc!=''){$('#pc').val(pc);}
		if(mn!=''){$('#mn').val(mn);}
		if(model!=''){$('#model').val(model);}
	}
	// Phone's Radio button for email form
	if($('.frm-row input#mob1').length !='0'){ 	
							$('.frm-row input[name=group1]:radio').click(function(){ 	if($(this).val()=='mobile'){ $('#land2').attr('checked','checked'); }
																				  		else{ $('#mob2').attr('checked','checked');	}
																		  });
							$('.frm-row input[name=group2]:radio').click(function(){	if($(this).val()=='mobile'){$('#land1').attr('checked','checked'); }
																				  		else{ $('#mob1').attr('checked','checked');}
																		  });
	}
    ///\brief Model search box
    if ($('#globalModelSearch')) {
        $('#globalModelSearch').bind('focus', function (e) { search_model('globalModelSearch'); }).attr("autocomplete", "off");
        $('#frm-search').bind('submit', function (e) {
            if ($('#globalModelSearch').val() != '') { showModelPage("globalModelSearch") } else {
                var newAlert = $('<div class="alert-content" title="Warning"> ' + selectmsg + '<br/> ex : SLT-A55 </div>');
                $('#globalModelSearch').after(newAlert);
                $(newAlert).MsgAlert({autoClose: true, wait: false, className: 'conditions_warning'});
            };
            return false;
        });
    };
	
	if($('#show-warr')){
		        $('#show-warr').bind('focus', function (e) { search_model('show-warr'); }).attr("autocomplete", "off");
		}
		
	if ($('.acc').length != '0') {
		$('.acc strong').click(function() {
			$(this).next().toggle('slow');
			$(this).toggleClass('ui-state-active');
			return false;
		}).next().hide();	
	}
	if ($('.transvid').length != '0') {
		var $source = $('.transvid strong');
		var $target = $('.transvid .vid');		
		$source.each( function(i) {
			$target.hide();		
			$(this).css('cursor','pointer');
			var status=0;
			$(this).bind("click",function(e){
					if(status==0){
						$target.hide();
						$target.eq(i).show('slow');
						status=1;
					}else{
						$target.hide();
						status=0;
					}
			});
		});
	}

    if ($('#acc_p').length != '0') {
        $('#acc_p').accordion({
            autoheight: false,
            header: 'strong'
        });
    };
    ///\brief Model search box for the mail form
    if ($('#kasaform')) {
        $('#model').bind('focus', function (e) {
            search_model('model');
        }).attr("autocomplete", "off");
    };

    ///\brief sparrow search box
    if ($('#search-sparrow')) {
        $('#search-sparrow').bind('focus', function (e) { search_model('search-sparrow'); }).attr("autocomplete", "off");
        $('#sparrow-search').bind('submit', function (e) {
            if ($('#search-sparrow').val() != '') { showSparrow(); }
            return false;
        });
    };
    if ($('#show_search')) {
        $('#show_search').bind('click', function (e) { $('#hidden_fb').show('slow'); $('.figure').addClass('paddme'); });
    };

    if ($('a.tooltip').length != '0') {
        $("a.tooltip").tooltip({
            bodyHandler: function () {
                return $($(this).attr("href")).html();
            },
            showURL: false,
            track: true
        });
    };

    if ($('a.connectbox').length != '0') {
        var connectbox = $(".content").ariaLightbox({
            imageArray: "a.connectbox",
            altText: function () {
                // $(this) is the triggered element (in this case the link)
                return "Picture opened by link: " + $(this).text();
            },
            descText: function () {
                return $(this).attr("title");
            },
            useDimmer: false,
            titleText: function () {
                //return "All pictures in Text";
                return $(this).text();
            },
            prevText: "See previous",
            nextText: "See next",
            em: true,
            makeHover: false
        });
    };

    /*****************VAIO SCRIPTS in GENESIS********************/

    if ($('.article').length) { collapseall(); }

    /*****************Feedback slider *******************
    $("#slider").slider({ value: 8, range: "min", min: 0, max: 10, step: 1, slide: function (event, ui) { $("#rate").val(ui.value); } });*/

    $(".rateIt input").click(function () {
        //var rating = $("#rate").val();
		var rating = $("#rate option:selected").val();
		rating==''? rating='8' : rating=rating;
		if (rating!= -1){
			var feedbacktext = $("#feedbacktext").val();
			storeFBInfoInDB(rating, feedbacktext);
			$(".rateIt").empty();
			var commenText = '<div class="comment"><h2 class="lite">' + thanks + '</h2>';
			if (feedbacktext.trim() != '') { commenText += '<p>' + thankscomment + '</p>' };
			commenText += '</div><hr class="clear" /> ';
			$(".rateIt").html(commenText);
		}
    });

    //
    $(".tab_content").hide(); //Hide all content
    $(".tab_content:first").addClass("active").show();		
			
		$("#updatebox .tabs li").each(function (i) {
			//hide all boxes and show 3 first numbers
			//$("#updatebox .tabs li").hide();
			//$("#updatebox .tabs li").eq(0).show();
			//$("#updatebox .tabs li").eq(1).show();
			//$("#updatebox .tabs li").eq(2).show();
			
			$(this).bind("click", function (e) {
				$("#updatebox div").hide();
				$("#updatebox div").eq(i).fadeIn();
				$("#updatebox .tabs li").removeClass('active');
				$(this).addClass('active');
				//clearTimeout(t);				
			});			
		});	

    /*****************glossary ********************/

    if ($('.glossary').length != '0') {
        $(".answer").hide();
        $(".showAnswer").click(function () {
            $(this).next(".answer").animate({ height: "toggle" }, 100);
            $(this).toggleClass('open');
        });
    }
	/* Show or hide the tip for genuine*/
    if ($('.specs').length != '0') {
        $(".answer").hide();
        $(".showAnswer").click(function () {
            $(this).children(".answer").animate({ height: "toggle" }, 100);
            $(this).toggleClass('open');
        });
    }
	/*show or hide the extra detail the italian mailform */
    if ($('.pim').length != '0') {
        $(".answer").hide();
        $(".showAnswer").click(function () {
            $(this).next(".answer").animate({ height: "toggle" }, 100);
            $(this).toggleClass('open');
        });
    }	
	/* show or hide the adaptor info for NEX cameras and camcorder*/
	if ($('.ea1').length != '0') {
        $(".ea1").hide();
        $("#ihaveea1").click(function () {
		   waitImg();
            $(".ea1").delay(400).animate({ height: "toggle" }, 100);
			setTimeout(function() { resolvedImg() }, 400);
			CurrentPage = window.location.href;
			if ( CurrentPage.indexOf( "#ea2" ) != -1 ) {	
				NewPage = CurrentPage.replace( '#ea2', '#ea1' );
			}else if( CurrentPage.indexOf( "#ea1" ) != -1 ){
				NewPage = CurrentPage.replace( '#ea1', '' );
			}else{
				NewPage = CurrentPage+"#ea1";
			}location=NewPage;

        });
    }
	if ($('.ea2').length != '0') {
        $(".ea2").hide();
        $("#ihaveea2").click(function () {
		   waitImg();
            $(".ea2").delay(800).animate({ height: "toggle" }, 100);
			setTimeout(function() { resolvedImg() }, 800);
			CurrentPage = window.location.href;
			if ( CurrentPage.indexOf( "#ea1" ) != -1 ) {	
				NewPage = CurrentPage.replace( '#ea1', '#ea2' );
			}else if( CurrentPage.indexOf( "#ea2" ) != -1 ){
				NewPage = CurrentPage.replace( '#ea2', '' );
			}else{
				NewPage = CurrentPage+"#ea2";
			}location=NewPage;        });
    }	
	
    /*****************videotransfer ******************

    if ($('#transvid').length != '0') {
        hideVideos();
        hideTroubleInfo();
        hideTroubleCat();
    };**/
  /***************** link to manual turnaround ******************
	if ($('#link-to-manuals').length != '0') {
		
		var url_repl = "javascript:model_popup('page','/support/"+s.prop3+"/modal-box/manuals/"+model_used+"','842','300',agree,'','Close','','cntAccessoriesModelPopup')";
		$('#link-to-manuals').attr('href',url_repl);
		}
**/
});			